问题
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