我正在尝试在win7 64下用mex为MATLAB 2013a 64编译c代码。
http://www.cs.cornell.edu/People/tj/svm%5Flight/svm_perf.html
根据这个网站的信息,Linux接口是由windows完成的,但只适用于SVMPerf和MACos,并且不能在windows下编译
http://www.aic.uniovi.es/~oluaces/Oscars_Home_Page/Personal.html
为此,我安装了gnumex,以便能够访问用于MATLAB的gcc,这是可以的。
然后我用mex编译,并根据SVMPerf中的make文件为所有涉及到的c程序创建目标文件。
还编写了mex_interface.cpp文件,用于LINUX下的MATLAB接口。但是,当我尝试链接所有文件时,我得到了以下与my_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 我相信它指向这个代码。my_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发布于 2015-01-13 02:59:23
看起来您遇到的问题与MEX无关,因为main函数被多次声明。这使得编译器很难知道从哪里开始运行代码。如果您有要在svm_learn_main或svm_struct_main中使用的公共函数,则需要将这些函数与包含主函数的文件分开。
发布于 2015-01-13 04:12:23
mex -largeArrayDims -DWIN -output svm_perf_classify mex_interface.cpp svm_perf_classify没有源文件扩展名(.c或.cpp或其他),因此它被编译器视为可执行文件。
https://stackoverflow.com/questions/27904366
复制相似问题