c++ - 使用外部 C++ 代码从 MATLAB 代码生成 C 代码
问题描述
我正在尝试使用一些外部 C++ 代码从 MATLAB 代码生成 C 代码。为了调试我的问题,我做了一个简单的例子。我将 foo.cpp 创建为:
#include "foo.h"
using namespace std;
double foo(double in1, double in2)
{
return in1 + in2;
}
带有名为 foo.h 的头文件:
double foo(double in1, double in2);
然后,我写了一个MATALB代码:
function r = callfoo(x,y)
r=1.1;
if coder.target('MATLAB')
% Executing in MATLAB, call MATLAB equivalent of
% C function foo
r = x + y;
else
% Executing in generated code, call C function foo
coder.updateBuildInfo('addSourceFiles','foo.cpp');
coder.cinclude('foo.h');
r = coder.ceval('foo', x, y);
end
end
但它无法生成 C 代码,因为我从 coder 收到这条消息时失败了:
构建错误:C 编译器产生错误。有关详细信息,请参阅构建日志。
当我指出更多细节时,它指向我:https ://www.mathworks.com/help///coder/ug/compiler-and-linker-errors.html
这个例子我取自 Mathworks,实际上(https://www.mathworks.com/help/simulink/slref/coder.ceval.html)。但是,他们的外部代码是 C,我的是 C++。
如何从生成的 C 代码中调用外部 C++ 代码?
解决方案
推荐阅读
- python - 记录导致行值比较变化的确切值python
- c# - 从 ChildVM 获取必要的 ViewModel 并将其设置为 ParentVM 中的属性
- javascript - 如何在继续之前等待所有文件被读取并执行所有回调
- c# - C# Entity Framework 6 - 选择列
- continuous-integration - 将文件保存在环境变量中
- python - 在Python中比较2个字符串的最有效方法是什么
- flutter - 清除 TextField 抖动时的错误
- matlab - 为什么我得到 fminsearch 未定义函数错误
- ios - 显示相机视图的 ImageView 'On-Top'
- sql - 提高查询的性能