C++ MEX编译错误

C++ MEX编译错误,c++,c,linux,matlab,mex,C++,C,Linux,Matlab,Mex,我正在尝试在win7 64下用mex为MATLAB 2013a 64编译c代码 根据该网站提供的信息,SVMPerf MATLAB接口由O Luaces完成 但仅适用于Linux和MACos,它不在windows下编译 为此,我安装了gnumex以访问gccformatlab,这是可以的 然后,我用mex编译,并根据需要为所有涉及的c程序创建对象文件 从SVMPerf生成文件 我还编译了mex_interface.cpp文件,该文件用于LINUX下的MATLAB接口。 但是,当我尝试链接所有

我正在尝试在win7 64下用mex为MATLAB 2013a 64编译c代码

根据该网站提供的信息,SVMPerf MATLAB接口由O Luaces完成 但仅适用于Linux和MACos,它不在windows下编译

为此,我安装了gnumex以访问gccformatlab,这是可以的

然后,我用mex编译,并根据需要为所有涉及的c程序创建对象文件 从SVMPerf生成文件

我还编译了mex_interface.cpp文件,该文件用于LINUX下的MATLAB接口。 但是,当我尝试链接所有文件时,我会遇到以下与我的\u malloc相关的错误

svm_learn_main.obj:svm_learn_main.c:(.text+0x470): first defined here 
svm_struct_main.obj:svm_struct_main.c:(.text.startup+0x0): multiple definition of
`main' 
svm_learn_main.obj:svm_learn_main.c:(.text.startup+0x0): first defined here 
Cannot export mexFunction: symbol not defined 
mex_interface.obj:mex_interface.cpp:(.text+0x94): undefined reference to  
`my_malloc(unsigned long long)' 
mex_interface.obj:mex_interface.cpp:(.text+0x218): undefined reference to 
`my_malloc(unsigned long long)' 
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.0/../../../../x86_64-w64-mingw32 
/bin/ld.exe: mex_interface.obj: bad reloc address 0x0 in section `.pdata' 
collect2.exe: error: ld returned 1 exit status 
link command: gcc -shared C:\Users\KRZYSZ~1\AppData\Roaming\MATHWO~1\MATLAB\R2013a  
\gnumex\mex.def -o svm_perf_classify.mexw64 -LC:\Users\KRZYSZ~1\AppData\Roaming
\MATHWO~1\MATLAB\R2013a\gnumex -s mex_interface.obj my_malloc.obj svm_learn_main.obj
svm_learn.obj svm_common.obj svm_hideo.obj svm_struct_learn.obj 
svm_struct_classify.obj svm_struct_common.obj svm_struct_main.obj svm_struct_api.obj   
svm_struct_classify.obj svm_struct_common.obj svm_struct_main.obj -llibmx -llibmex  
-llibmat 
我相信它指向了这个代码。我的_malloc编译正常。有什么想法吗

void create_argc_argv(const mxArray *options,int *argc,char **argv[]) {
// convert the matlab string of options into a CLI-like input (argc and argv)
*argc=1;

mwSize buflen = mxGetN(options)*sizeof(mxChar)+1;
char *buf = mxMalloc(buflen);
// Copy the string data into buf
mxGetString(options, buf, buflen);
// and separate in argv[]
char **ap, **argv_ptr=(char **)my_malloc(MAX_ARGVS*sizeof(char *));
argv_ptr[0]="OLR";
for (ap = (argv_ptr+1); (*ap = strsep(&buf, " \t")) != NULL;)
    if (**ap != '\0') {
        (*argc)++;
        if (++ap >= &argv_ptr[MAX_ARGVS])
            break;
    }
// 'buf' shouldn't be freed, since it is converted to the different 'argv[i]'
// by setting to '\0' the tabs and white spaces between options
// (this trick was taken from the 'strsep' man page)
// so, we don't make mxFree(buf);

*argv=argv_ptr;
}
我的mex命令如下所示

mex -largeArrayDims -DWIN -output svm_perf_classify mex_interface.cpp    
svm_learn_main.obj svm_learn.obj svm_common.obj svm_hideo.obj svm_struct_learn.obj 
svm_struct_classify.obj svm_struct_common.obj svm_struct_main.obj svm_struct_api.obj 
svm_struct_classify.obj svm_struct_common.obj svm_struct_main.obj

看起来您遇到的问题与MEX无关,因为主函数被多次声明。这使得编译器很难知道从哪里开始运行代码。如果要在svm_learn_main或svm_struct_main中使用公共函数,则需要将这些函数与包含主函数的文件分开

mex -largeArrayDims -DWIN -output svm_perf_classify mex_interface.cpp    

svm_perf_classify没有源文件扩展名(.c或.cpp或其他),因此编译器将其视为可执行文件

这段代码正在编译,所以我认为多个定义不是问题。我只是按照原始makefile中的receipi,我认为是ok,这是输出名。扩展取决于操作系统版本。所以这里一切都好