用GNU编译器生成独立的MEX文件,包括库 [英] Generating standalone MEX file with GNU compilers, including libraries

查看:139
本文介绍了用GNU编译器生成独立的MEX文件,包括库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写并编译了一个MEX函数,可以从MATLAB例程中调用,它在我的电脑上运行良好。但是,当我尝试让不同的计算机运行我的例程时,它会打破一个错误,指出模块不存在。我的MEX功能引用了GSL库和其他一些库。我想知道是否可以编译我的MEX函数,以便它是独立的。当我说独立时,我的意思是如果我只是将MEX文件复制到另一台计算机上,并且没有安装库或编译器,它仍然可以工作。



谢谢!

解决方案

您的外部库需要是静态库。然后有很多方法可以做到这一点:$ b​​
$ b


  • 在运行mex(gcc选项)时添加一个'-static'链接器标志。

  • 而不是使用'-lgsl'添加'/path/to/libgsl.a'(Linux)

  • 或者直接从您在mex文件中使用的库到mex命令



mex文件本身仍然只能在兼容系统上运行(64位与32位,匹配libc版本)。



在linux上,检查您是否正确编译了类型'ldd mexfile.mexext'。您的外部库不应显示在列表中。


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!

解决方案

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.

这篇关于用GNU编译器生成独立的MEX文件,包括库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆