【问题标题】:Relocation R_X86_64_PC32 against undefined hidden symbol `__dso_handle' can not be used when making a shared object重定位 R_X86_64_PC32 针对未定义的隐藏符号 `__dso_handle' 在制作共享对象时不能使用
【发布时间】:2020-01-17 07:18:36
【问题描述】:

我想在 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

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

【问题讨论】:

  • 链接期间似乎缺少 vDSO 库。

标签: python c++ c swig ld


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    相关资源
    最近更新 更多