matlab - 使用 boolean_T 的 Matlab 编码器
问题描述
我正在尝试为一个简单的函数 Matlab 函数生成 C 代码:
function[] = myfunc()
%#codegen
fprintf('Executing myfun\n');
fid = fopen('file_created_by_myfun.txt','w');
fwrite(fid,'This is written by myfun upon execution');
fclose(fid);
end
但是,在生成的代码中使用了变量类型 boolean_T 但未在任何地方声明。在我看来,没有包含带有声明的标题。生成代码的脚本是:
config_obj = coder.config('exe');
config_obj.GenCodeOnly = 'on';
codegen -config config_obj myfun
通过使用自定义 makefile 调用make
,我收到以下错误消息:
error: unknown type name 'boolean_T'
error: 'false' undeclared (first use in this function)
error: 'true' undeclared (first use in this function)
我可以要求单个文件并添加自定义代码:
config_obj = coder.FilePArtitioningMethod('SingleFile');
config_obj.CustomSourceCode = ['typedef unsigned int boolean_T;',newline,...
'#define true 1U',newline,...
'#define false 0U'];
这将允许我正确编译代码,但这是一个糟糕的解决方案,因为我不想生成单个文件,并且添加的源代码不会根据需要包含在每个文件中。
有什么办法可以避免使用 boolean_T 类型?或者有一些我应该使用的指令,但我错过了?
解决方案
boolean_T 和可能的其他类型(如 int_T)在未生成但随 MATLAB 提供的头文件中定义。通常定义在 tmwtypes.h 中,您可以在 /extern/include 中找到。生成的 makefile 在包含目录列表中包含指向此路径的路径作为编译器的选项。如果您不使用生成的 makefile,则需要手动将这些头文件的路径添加到编译器选项中。
推荐阅读
- python-3.x - 如何将更大的数组保存和访问到 hdf5 文件:内存错误?
- python - Python:如何从 txt 文件中找到最接近的匹配句子
- javascript - Window.location Javascript JS 重定向
- ruby-on-rails - 来自类中私有方法的 NoMethodError(未定义方法)
- aws-lambda - AWS Lambda - 与 Apple 推送通知服务通信
- android - Reack Native 版本 .apk 在更高版本的 android 设备中崩溃,地理定位权限被拒绝错误
- python - (美汤) 获取按钮标签内的数据
- visual-studio - 如何使用 Visual Studio 2017 构建 Gtk#/Mono 应用程序
- linux - 在汇编中附加两个字符串
- typescript - 使用函数接口来确保参数但推断更具体的返回类型