如何将Python C模块与`ld`链接起来。对__dso_handle'的未定义引用

时间:2013-04-22 09:53:28

标签: python linux ld

我目前的命令:

c++ -fPIC -c algo_cython.cpp
ld -shared algo_cython.o -L/usr/lib/gcc/x86_64-linux-gnu/4.7 -lc -lstdc++   -o algo_cython.so

错误:

algo_cython.o: In function `__static_initialization_and_destruction_0(int, int)':
algo_cython.cpp:(.text+0x83e4): undefined reference to `__dso_handle'
ld: algo_cython.o: relocation R_X86_64_PC32 against undefined hidden symbol `__dso_handle' can not be used when making a shared object
ld: final link failed: Bad value

1 个答案:

答案 0 :(得分:1)

使用选项algo_cython.cpp编译-fPIC - 如果没有此标志,则无法在intel上编译64位的共享对象,因此编译行应为:

c++ -fPIC -c algo_cython.cpp

另外,我实际上使用编译器驱动程序来生成共享对象,而不是直接调用ld,即你可以使用:

c++ -shared algo_cython.o -L/usr/lib/gcc/x86_64-linux-gnu/4.7 -lc -lstdc++   -o algo_cython.so

除非你真的想要做一些无法从编译器驱动程序驱动的东西,否则直接调用ld不是你想要做的。

相关问题