【问题标题】:Using Matlab C++ compiler to convert C++ code into Matlab使用 Matlab C++ 编译器将 C++ 代码转换为 Matlab
【发布时间】:2018-11-08 21:25:13
【问题描述】:

我正在尝试在 Matlab 中使用 MinGW-w64 编译器。我已经安装了它,Matlab 可以识别编译器。我的问题有两个:

1) 我无法将所有 .c 代码编译成头文件。我输入了

 mex -output HTKToolsFolder *.c
 Building with 'MinGW64 Compiler (C)'.

得到了

Error using mex
C:\Users\username\Documents\MATLAB\MatlabHTK\htk\HTKTools\HBuild.c:39:46:    fatal error: HShell.h: No such
file or directory
 #include "HShell.h" /* HMM ToolKit Modules */
                                          ^
compilation terminated.

我不确定 .h 扩展名是什么。该文件位于另一个文件夹中,但如果我告诉 Matlab 编译 .h 文件,它无法识别文件扩展名

mex -output hfilescompiled *.h
Error using mex
Unknown file extension '.h'.

如果有帮助,某些 .c 文件会调用 HShell.h

第二个问题是,一旦第 1 个问题得到解答,我可以将它应用到包含许多 C++ 代码文件夹的目录吗?还是我必须对每个文件夹都使用 mex 命令?

我看过 Matlab 教程:https://www.mathworks.com/solutions/matlab-and-c.html,还阅读了 mex 和 loadlibrary 的 Matlab 帮助文件。

非常感谢任何建议,因为这是我第一次混合 C++ 和 Matlab。提前致谢!

【问题讨论】:

    标签: c++ matlab compiler-errors mex


    【解决方案1】:

    你想这样做:

    mex HBuild.c -IC:\Path\To\H\Files
    

    其中C:\Path\To\H\Files 是包含HShell.h 的目录。

    这将创建一个名为 HBuild 的 MEX 文件(假设 HBuild.c 包含一个 mexFunction 函数,并且不存在其他依赖项)。

    如果您执行mex *.c,则该目录中的所有 C 源文件将合并为一个 MEX 文件。我怀疑这是你想要的。您需要为要构建的每个 MEX 文件调用 mex。每个 MEX 文件都将成为 MATLAB 中可用的函数。

    【讨论】:

      猜你喜欢
      • 2013-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-05
      • 2023-03-27
      • 2014-05-21
      • 1970-01-01
      • 2011-03-27
      相关资源
      最近更新 更多