MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   在os x上将python嵌入到matlab mex文件中 (https://www.labfans.com/bbs/showthread.php?t=22885)

poster 2019-12-10 16:49

在os x上将python嵌入到matlab mex文件中
 
我正在尝试将Python嵌入OS X上的MATLAB mex函数中。我已经看到可以做到这一点的参考资料(例如[URL="http://www.daniweb.com/forums/thread171969.html#"]here[/URL] ),但是我找不到任何OS X特定的信息。到目前为止,我可以成功构建嵌入式Python(因此,我的链接器标记必须正确),并且还可以毫无问题地使用默认选项构建示例mex文件:

jm-g26b101:mex robince$ cat pytestnomex.c #include int main() { Py_Initialize(); PyRun_SimpleString("print 'hello'"); Py_Finalize(); return 0; } jm-g26b101:mex robince$ gcc -arch i386 pytestnomex.c -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -L/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/config -ldl -lpython2.5 jm-g26b101:mex robince$ ./a.out hello 但是,当我尝试构建嵌入Python的mex文件时,遇到了不确定的main符号问题。这是我的混合函数:

#include #include void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) { mexPrintf("hello1\n"); Py_Initialize(); PyRun_SimpleString("print 'hello from python'"); Py_Finalize(); } 这是mex编译步骤:

jm-g26b101:mex robince$ gcc -c -I/Applications/MATLAB_R2009a.app/extern/include -I/Applications/MATLAB_R2009a.app/simulink/include -DMATLAB_MEX_FILE -arch i386 -I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -DMX_COMPAT_32 -O2 -DNDEBUG "pytest.c" jm-g26b101:mex robince$ gcc -O -arch i386 -L/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/config -ldl -lpython2.5 -o "pytest.mexmaci" pytest.o -L/Applications/MATLAB_R2009a.app/bin/maci -lmx -lmex -lmat -lstdc++ Undefined symbols: "_main", referenced from: start in crt1.10.6.o ld: symbol(s) not found collect2: ld returned 1 exit status 我试过使用arch设置(我添加了-arch i386来尝试使所有内容保持32bit-我正在使用python.org 32 bit 2.5构建),以及链接器标志的顺序,但是还无法去任何地方。在网上也找不到太多。有人对我如何构建它有任何想法吗?

[编辑:可能应该添加我在带有MATLAB 7.8(r2009a),Python 2.5.4(python.org)的OS X 10.6.1上-我已经尝试了gcc-4.0和gcc-4.2(苹果)]


回答:
我想我找到了答案-通过添加神秘的苹果链接器标志:

-undefined dynamic_lookup -bundle 我能够建立它,而且看起来工作正常。如果有人对OS X上的这些标志或库处理有任何参考,我将非常感兴趣。现在我看到他们,我记得过去曾经被同样的事情所困扰-但是我找不到任何有关它们实际工作以及为什么/何时需要它们的文档。



[url=https://stackoverflow.com/questions/1700628]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 10:33

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.