簡體   English   中英

提升python庫鏈接問題-未定義符號

[英]boost python library linking issue — undefined symbol

我正在使用為python3構建的boost-python來公開一個簡單的hello-world程序。 可以在這里找到示例: https : //github.com/TNG/boost-python-examples/blob/master/01-HelloWorld/hello.cpp

我運行以下命令來獲取共享庫:

g++ -fPIC -c -I/usr/include/python3.4m -I/usr/include/python3.4m  -Wno-unused-result -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security  -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -L/usr/lib/x86_64-linux-gnu/libboost_python-py34 hello.cpp

g++ -shared hello.o -o hello.so

之后,我運行python3 -c 'import hello'命令,並得到以下錯誤:Traceback(最近一次調用為last):

文件“”,第1行,位於ImportError中:hello.so:未定義符號:_ZTIN5boost6python7objects21py_function_impl_baseE

我部分理解這個問題可能是因為我的boost-python安裝可能是為其他python版本(例如python2.7)構建的。 當我運行命令時:

ls /usr/lib/x86_64-linux-gnu/libboost_python*.so

有三個.so文件:

1. libboost_python-py27.so
2. libboost_python-py34.so
3. libboost_python.so

如何解決這個問題?

使用pkg-config檢索boost庫的ldflags和cflags

安裝miniconda可能是您的選擇。 https://conda.io/miniconda.html

這將提供一個完整的,隔離的python環境。 然后您可以conda install boost

我已經在系統上對此進行了測試,並且效果很好。 我從http://www.shocksolution.com/python-basics-tutorials-and-examples/linking-python-and-c-with-boostpython/修改了Makefile

我的Makefile可以在這里找到: https : //github.com/grelleum/boost-python-with-anaconda

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM