python - 制作共享对象时,无法使用针对未定义隐藏符号 `__dso_handle' 的重定位 R_X86_64_PC32

标签 python c++ c swig ld

我想在 Python 中使用 C++ 函数。因此,我决定尝试使用 SWIG 来实现此目的。 首先,我运行命令:

swig -python test.i

然后用g++-6.2编译如下:

g++-6.2 -c test.cpp test_wrap.c -fPIC -I /usr/include/python3.6m

到目前为止,一切正常,但在必须创建链接的最后一步时出现问题。我运行命令:

ld -shared test.o test_wrap.o -o _test.so

按照 Swig tutorial 中的建议,但我收到以下错误:

test.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x66): undefined reference to `__dso_handle'
ld: test.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

有人知道如何解决这个问题吗?

最佳答案

您没有与 ld 命令链接。您链接到与编译时相同的 $(CC)$(CXX) (gccg++) ,使用适合链接的选项。它将使用应生成的 ABI、目标格式等的正确命令行选项来驱动后端链接器 ld

这样做,它应该可以正常工作:

g++-6.2 -shared test.o test_wrap.o -o _test.so

关于python - 制作共享对象时,无法使用针对未定义隐藏符号 `__dso_handle' 的重定位 R_X86_64_PC32,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57957080/

相关文章:

python - hdf5/h5py ImportError : libhdf5. so.7

python - 如何每隔x秒重复执行一个函数?

c++ - 使用 JNA 从 Java 调用 C++ dll 方法并避免 Method Name Mangling

python - 如何使用 Fabric 使用 nohup 启动后台进程?

python - 使用 azure cli 将 python 应用程序部署到现有的 azure 应用程序服务

c - 我如何在 (GNU) C 中编写一个代理函数来连接两个不同的调用约定?

c++ - 尝试从 c 执行任何二进制文件

c - 枚举桌面上的所有窗口句柄

c++ - Qt/OpenGL : Am I using PBO correctly ?

c++ - vector 不是模板?