【问题标题】:Matlab code to C using Matlab coder使用 Matlab 编码器将 Matlab 代码转换为 C
【发布时间】:2013-01-18 09:01:06
【问题描述】:

我有一些工作的 Matlab 代码,我尝试使用 Matlab 编码器将其转换为 C 代码。我收到此错误:

18   c:\users\bla\project\strcmpi.h(79) : warning C4028: formal parameter 2 different from declaration
19   c:\users\bla\project\strcmpi.h(79) : error C2371: 'strcmpi' : redefinition; different basic types
20           c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\string.h(245) : see declaration of 'strcmpi'
21   NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.EXE"' : return code '0x2'
22   Stop.
23   The make command returned an error of 2
24   'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
25   operable program or batch file.

它看起来对我来说非常 C 特定(我不是一个精通 C 的程序员)。谁能指出我正确的方向来克服这个错误?谢谢。

PS:

这里是一些改编的 Matlab 代码:

if(strcmpi(parameters.x,'bladibla') == 1)

    % some code

else

    % some more code

end

其中“参数”是一个结构。我想坚持我的结构,但如果有更好的方法来实现上述目标,尤其是在 Matlab 编码器和 C 的上下文中,请告诉我。

【问题讨论】:

  • 你是否在你的 Matlab 代码中使用 'strcmpi' 函数和 coder.ceval 之类的?包含代码的相关部分会有所帮助。
  • 感谢您的评论。我添加了一些 Matlab 代码(见 PS :)。

标签: c matlab visual-c++ matlab-coder


【解决方案1】:

关于 strcmpi()(不区分大小写的字符串比较)的问题在于它不是标准的 C 函数。因此,依赖于它但试图跨平台移植的代码有时必须提供自己的实现,同时如果可用则推迟到系统的实现。根据我的经验,项目自己的 strcmpi() 实现将受到配置选项的保护。如果你打开 c:\users\bla\project\strcmpi.h,你可能会看到类似这样的代码:

#ifndef CONFIG_STRCMPI_PRESENT
int strcmpi(const char *string1, const char *string2);
#endif  // CONFIG_STRCMPI_PRESENT

如果你看到这个,解决问题的诀窍可能是找到相关的 config.h 文件并取消注释以下行:

// #define CONFIG_STRCMPI_PRESENT

这只是根据我对类似问题的经验的猜测。

【讨论】:

  • 感谢您的回答。我添加了一些 Matlab 代码(见 PS :)。
  • strcmpi() 的高级用法不会有问题。问题是在代码库中有 2 种不同的 strcmpi() 定义。要解决这个问题,您需要删除其中一个 strcmpi() 实现,它可能是项目内置的(而不是系统版本)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-05
  • 2023-03-27
  • 2014-05-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多