首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MEX编译错误

MEX编译错误
EN

Stack Overflow用户
提问于 2015-01-12 22:34:05
回答 2查看 1K关注 0票数 0

我正在尝试在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相关的错误

代码语言:javascript
复制
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编译正常。有什么想法吗?

代码语言:javascript
复制
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命令如下所示

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2015-01-13 02:59:23

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

票数 0
EN

Stack Overflow用户

发布于 2015-01-13 04:12:23

代码语言:javascript
复制
mex -largeArrayDims -DWIN -output svm_perf_classify mex_interface.cpp    

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27904366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档