gpt4 book ai didi

c++ - 尝试使用 mex 为 MATLAB 编译多个 c++ 文件时出错

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:27:57 25 4
gpt4 key购买 nike

我在 Ubuntu 下使用 MATLAB 并希望使用 mex 编译一组 2 个带有头文件的 c++ 文件。我展示了一个基本示例和我遇到的错误。

此代码从 mexFunction 开始的 c++ 函数生成文本“hello”,并使用 mex 在 MATLAB 中编译 (mex mexTryAlex.cpp):

#include <mex.h>
#include <iostream>
using namespace std;

void newfunc(){
cout<<"hello\n";
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
newfunc();
}

而且一切正常。现在我尝试在 mex 中使用多个 文件和一个头文件。我创建了一个头文件try.h:

#ifndef try_h
#define try_h
void newfunc();
#endif

然后是新函数的文件try.cpp:

#include <mex.h>
#include <iostream>
#include <try.h>
using namespace std;

void newfunc(){
cout<<"hello\n";
}

这 3 个文件不能用 mex 编译:

>> mex  mexTryAlex.cpp try.cpp try.h

Warning: You are using gcc version "4.4.3-4ubuntu5)". The version
currently supported with MEX is "4.3.4".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/

try.cpp:4:17: error: try.h: No such file or directory
mex: compile of ' "try.cpp"' failed.
??? Error using ==> mex at 208
Unable to complete successfully.

使用 -I 选项的另一种尝试:

>> mex  -I mexTryAlex.cpp try.cpp try.h
Warning: You are using gcc version "4.4.3-4ubuntu5)". The version
currently supported with MEX is "4.3.4".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/

mexTryAlex.cpp:1:17: error: mex.h: No such file or directory
mexTryAlex.cpp:7: error: ‘mxArray’ has not been declared
mexTryAlex.cpp:7: error: ISO C++ forbids declaration of ‘mxArray’ with no type
mexTryAlex.cpp:7: error: expected ‘,’ or ‘...’ before ‘*’ token
mex: compile of ' "mexTryAlex.cpp"' failed.
??? Error using ==> mex at 208
Unable to complete successfully.

如何编译这些文件?

最佳答案

错误已通过使用修复

#include "try.h"

代替

 #include <try.h>  

在源文件中。

关于c++ - 尝试使用 mex 为 MATLAB 编译多个 c++ 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16149170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com