Generating standalone MEX file with GNU compilers, including libraries

纵饮孤独 提交于 2020-01-05 07:08:33

问题


I have written and compiled a MEX function to be called from a MATLAB routine, it runs great on my computer. However, when I try to have a different computer run my routine, it breaks with an error saying the module does not exist. My MEX function is referencing the GSL libraries, and some others. I want to know if it is possible to compile my MEX function so that is a standalone. When I say standalone I mean that if I just copy the MEX file to another computer, and there are no libraries or compilers installed, it will still work.

Thanks!


回答1:


Your external libraries need to be static libraries. Then there are a number of ways to do it:

  • add a '-static' linker flag when running mex (gcc option).
  • instead of using '-lgsl' add '/path/to/libgsl.a' (Linux)
  • or simply add the object files from the libraries you use in your mex files to the mex command

The mex file itself will still only run on a compatible system (64bit vs 32bit, matching libc version).

On linux, to check whether you have compiled correctly type 'ldd mexfile.mexext'. Your external libraries should not show in the list.



来源:https://stackoverflow.com/questions/12187169/generating-standalone-mex-file-with-gnu-compilers-including-libraries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!