0

我正在通过“Matlab coder”将 MATLAB 编写的函数转换为 C。获得转换后的文件后,转换后的函数始终将第一个输入参数作为const emlrtStack *sp. 现在,当我尝试在 VC++ 2013 上对其进行测试时,IntelliSense 给出了上述错误。

我手动尝试在emlrt.h文件中找到这个标识符,但那里没有这样的东西。我试图用两个输入参数转换一个简单的乘法函数[如c=mul(a,b) ],但除了ab之外,转换后的函数在函数内部还有这个额外的参数。(这意味着此参数不是特定于函数的)。

如果有人对此有解决方案或遇到过此类问题,请分享或帮助。

此外,如果有人知道如何简单地测试这些转换后的函数,那将是非常感谢的额外帮助。

4

1 回答 1

1

It is likely that the code that was generated for a MEX function rather than a standalone target. MEX functions are binaries written C, C++ or Fortran that can be called like a normal MATLAB function. Generating code to produce a MEX function allows two things. First, you can test your generated code in MATLAB because you can call the MEX function from MATLAB like any other function. Look for a file named mul_mex.mex* after you do code generation and try to call it: mul_mex(1,2). The other use for generating a MEX function is that it can often be faster than the MATLAB code from which it was generated. MEX functions are only used in the context of MATLAB.

The parameter emlrtStack* that you saw appears in MEX generated code to aid in runtime error reporting. It is not present in standalone code that is designed to be run outside of MATLAB.

If you want to use the generated code in Visual Studio, or outside of MATLAB you should choose one of the standalone targets, LIB, DLL, or EXE. This page shows how to change the output type. To summarize, if using the command line you could say:

cfg = coder.config('lib'); %or 'dll' or 'exe'
codegen mul -config cfg -args {1,2}

If using the project interface, you click on the Build tab and choose static library or shared library in the "Output type" dropdown menu.

I would recommend reading this example that demonstrates how to use a generated DLL in Visual Studio.

于 2014-09-24T10:25:20.823 回答