【问题标题】:i cant compile matlab generated code, it gives me a linker error what is the correct step i have to follow?我无法编译 matlab 生成的代码,它给了我一个链接器错误我必须遵循的正确步骤是什么?
【发布时间】:2014-04-15 01:39:50
【问题描述】:

我试图学习 matlab 到 C 的工作流程,我使用 matlab 编码器从这个 .m 文件生成 C/C++ 代码

  function c = simpleProduct(a,b) %#codegen
  c=a*b;

生成代码后,我的可视化 win32 c++ 项目如下所示。

#include <iostream>
#include "simpleProduct.h"  //matlab generated header file.
using namespace std;
void main(){
    cout<<simpleProduct(34,55);   //matlab generated funcion
}

我什至将项目属性中的“附加库”和“附加依赖项”配置到我生成的静态库中,但同样的问题一次又一次地发生。

从这段代码中我生成了一个静态库。在matlab上操作成功。但是当我包含生成的头文件并在visual studio中链接静态库并编译它时,它给了我这个错误。

Error   1   error LNK2019: unresolved external symbol "float __cdecl simpleProduct(float,float)" (?simpleProduct@@YAMMM@Z) referenced in function _main C:\Users\serakpc\Documents\Visual Studio 2010\Projects\chiraq\chiraq\source.obj chiraq

开发环境---- MATLAB 2012b, 视觉工作室 2012, 视觉工作室 2010,

【问题讨论】:

  • 函数定义在哪里?这听起来像是您没有正确链接或缺少函数定义代码。
  • 这里是 simpleproduct.c,看起来像 real32_T simpleProduct(real32_T a, real32_T b) { return a * b; }

标签: matlab visual-c++ matlab-deployment mixed-programming


【解决方案1】:

原因是你的visual studio项目找不到simpleProduct.dll

解决方案:当你将 MATLAB 分发到 Visual Studio 中时,它会生成(至少)四个文件,即

  1. simpleProduct.h

  2. simpleProduct.lib

  3. simpleProduct.dll

  4. simpleProduct.ctf

您需要将这4个文件复制到您的Visual Studio解决方案目录中,并将simpleProduct.lib添加到[Properties &gt; Linker &gt; Input]。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多