简体   繁体   English

Mac OS X将.so文件链接到动态库

[英]Mac OS X linking .so file to dynamic library

I'm trying to build a python package that is dependent on several libraries including boost, boost-python, and fftw. 我正在尝试构建一个依赖于几个库的python包,包括boost,boost-python和fftw。 I am able to compile the package without any errors, but when I try to run the program with the steme --help command, I get an error: 我能够编译该程序包而没有任何错误,但是当我尝试使用steme --help命令运行程序时,出现错误:

2016-08-11 15:07:55,571:ERROR: ImportError: dlopen(/Users/<>/.ENV/lib/python2.7/site-packages/STEME-1.9.1-py2.7-macosx-10.11-intel.egg/stempy/_release_build/_index.so, 2): Symbol not found: __ZN5boost6python6detail13current_scopeE
  Referenced from: /Users/<>/.ENV/lib/python2.7/site-packages/STEME-1.9.1-py2.7-macosx-10.11-intel.egg/stempy/_release_build/_index.so
  Expected in: flat namespace
 in /Users/<>/.ENV/lib/python2.7/site-packages/STEME-1.9.1-py2.7-macosx-10.11-intel.egg/stempy/_release_build/_index.so

My understanding is the the file _index.so is looking for the symbol __ZN5boost6python6detail13current_scopeE but can't find it. 我的理解是文件_index.so正在寻找符号__ZN5boost6python6detail13current_scopeE但找不到它。 Next I checked what libraries are linked to the _index.so file using otool -L : 接下来,我使用otool -L检查了哪些库链接到_index.so文件:

/Users/<>/.ENV/lib/python2.7/site-packages/STEME-1.9.1-py2.7-macosx-10.11-intel.egg/stempy/_release_build/_index.so:
    /usr/local/opt/fftw/lib/libfftw3.3.dylib (compatibility version 8.0.0, current version 8.4.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

Based on this, what I think is happening is that the boost-python dynamic library was not properly linked to _index.so during compilation. 基于此,我认为正在发生的事情是boost-python动态库在编译期间未正确链接到_index.so To check that I ran nm -g on the boost-python dylibs (which were installed using brew , along with the other mentioned dependencies). 要检查我是否在boost-python dylib上运行了nm -g (使用brew和其他提到的依赖项安装)。 The missing symbol was found in the libboost_python.dylib file: libboost_python.dylib文件中找到了丢失的符号:

0000000000031d08 S __ZN5boost6python6detail13current_scopeE

So, my next question is, how do I link the libboost_python.dylib file (located at /usr/local/Cellar/boost-python/1.61.0/lib ) to the _index.so file? 因此,我的下一个问题是,如何将libboost_python.dylib文件(位于/usr/local/Cellar/boost-python/1.61.0/lib )链接到_index.so文件? Will that even fix the problem? 这样甚至可以解决问题吗? Is there some compiler flag that I need to set to make sure the build is properly linked? 我是否需要设置一些编译器标志以确保正确链接内部版本?

Try to include /usr/local/Cellar/boost-python/1.61.0/lib in your path when you launch the binary. 启动二进制文件时,请尝试在路径中包含/usr/local/Cellar/boost-python/1.61.0/lib Something like 就像是

$ export PATH=$PATH:/usr/local/Cellar/boost-python/1.61.0/lib
$ ./your-binary

The link to the library is there otherwise you could not have found it via otool . 该库的链接在那里,否则您无法通过otool找到它。 I think that the program is not finding the shared library as it cannot be found in the PATH. 我认为该程序找不到共享库,因为无法在PATH中找到它。

This error seems very similar to the "DDL not found" error type in windows, which can be fixed by supplying the DDL either in the current dir or in the PATH. 该错误似乎与Windows中的“找不到DDL”错误类型非常相似,可以通过在当前目录或PATH中提供DDL来修复该错误类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM