Ld错误的符号
我正在使用 boost.python 库构建应用程序。我想链接它。这是代码:
#include <boost/python.hpp>
using namespace boost::python;
// Boost.python definitions to expose classes to Python
BOOST_PYTHON_MODULE(arrayClasses) {
}
以及它的 makefile:
PYTHON = /usr/include/python2.7
BOOST_INC = /usr/include
BOOST_LIB = /usr/lib
TARGET = arrayClasses
$(TARGET).so: $(TARGET).o
g++ -shared -Wl,--export-dynamic \
$(TARGET).o -L$(BOOST_LIB) -lboost_python \
-L/usr/lib/python2.7/config -lpython2.7 \
-o $(TARGET).so
$(TARGET).o: $(TARGET).cpp
g++ -I$(PYTHON) -I$(BOOST_INC) -c -fPIC $(TARGET).cpp
当我编译它时,我得到:
g++ -shared -Wl,--export-dynamic \
arrayClasses.o -L/usr/lib -lboost_python \
-L/usr/lib/python2.7/config -lpython2.7 \
-o arrayClasses.so
/usr/bin/ld: arrayClasses.o: relocation R_X86_64_32 against `init_module_arrayClasses()' can not be used when making a shared object; recompile with -fPIC
arrayClasses.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
有什么问题吗?
I'm buildnig application with boost.python library. I want to link it. Here is the code:
#include <boost/python.hpp>
using namespace boost::python;
// Boost.python definitions to expose classes to Python
BOOST_PYTHON_MODULE(arrayClasses) {
}
And makefile for it:
PYTHON = /usr/include/python2.7
BOOST_INC = /usr/include
BOOST_LIB = /usr/lib
TARGET = arrayClasses
$(TARGET).so: $(TARGET).o
g++ -shared -Wl,--export-dynamic \
$(TARGET).o -L$(BOOST_LIB) -lboost_python \
-L/usr/lib/python2.7/config -lpython2.7 \
-o $(TARGET).so
$(TARGET).o: $(TARGET).cpp
g++ -I$(PYTHON) -I$(BOOST_INC) -c -fPIC $(TARGET).cpp
When I compile it I get:
g++ -shared -Wl,--export-dynamic \
arrayClasses.o -L/usr/lib -lboost_python \
-L/usr/lib/python2.7/config -lpython2.7 \
-o arrayClasses.so
/usr/bin/ld: arrayClasses.o: relocation R_X86_64_32 against `init_module_arrayClasses()' can not be used when making a shared object; recompile with -fPIC
arrayClasses.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
What's wrong is there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:忽略它。它使用 Python 2.6 和 Boost 1.44 在 32 位 Ubuntu 系统上为我进行编译。正如 Ignacio Vazquez-Abrams 指出的那样,您可能应该检查您的 Python 和 Boost 库是否是针对相同的架构编译的。
Edit: Ignore that. This compiles for me on a 32-bit Ubuntu system using Python 2.6 and Boost 1.44. As Ignacio Vazquez-Abrams pointed out, you should probably check if your Python and Boost libraries were compiled for the same architecture.