【问题标题】:Relocation R_X86_64_PC32 against undefined symbol can not be used when making a shared object; recompile with -fPIC制作共享对象时不能使用针对未定义符号的重定位 R_X86_64_PC32;使用 -fPIC 重新编译
【发布时间】:2019-02-01 00:35:30
【问题描述】:

我最近将 gSOAP 从 2.8.7 升级到了 2.8.76。我不得不为升级做一些小的代码调整,但升级后代码不会像以前那样链接到计算机上。

我正在尝试使用 gSOAP 在使用 g++ 4.9.2 的计算机上创建一个共享库。我已将代码压缩以创建一个测试用例,该测试用例稍微简化了一些事情,以尝试确定故障发生的位置。

gSOAP 在我运行时会生成一些 ebaySoapLib* 文件:

/usr/local/bin/soapcpp2 -z1 -C -w -x -n -pebaySoapLib -qebaySoapLib -I/usr/local/include/gsoap:/usr/local/share/gsoap:/usr/local/share/gsoap/import ebaySvc.h

-z1 选项是为了保持与 gSOAP 2.8.7 相似。

如果我跑:

g++  -fPIC -c ebaySoapLibClientLib.cpp
g++  -shared -fPIC -o test.so ebaySoapLibClientLib.o

我得到错误:

/usr/bin/ld: ebaySoapLibClientLib.o: relocation R_X86_64_PC32 against
undefined symbol `soap_serializeheader' can not be used when making a
shared object; recompile with -fPIC

/usr/bin/ld: final link failed: Bad value

collect2: error: ld returned 1 exit status

我将确切的文件复制到另一台运行 g++ 6.3.0 的计算机上(不确定编译器版本是否重要或现在),这可以正常编译和链接。

文件 ebaySoapLibClientLib.cpp 包含:

#define SOAP_FMAC3 static
#include "ebaySoapLibC.cpp"
#include "ebaySoapLibClient.cpp"

现在,如果我删除该行:

#define SOAP_FMAC3 static

然后代码在两台计算机上都可以正常编译。

我不知道我需要做些什么来使其与 g++ 4.9.2 计算机正常链接。我可以取出#define,这样函数就不会被定义为静态并让它工作,但问题是 WHY 因为 gSOAP 将它放在那里是有原因的,它在将这些函数设置为静态的 g++ 6.3.0。

【问题讨论】:

  • 奇怪,所有系统库都应该可以工作...soap_serializeheader 来自哪里?

标签: c++ linker g++ shared-libraries gsoap


【解决方案1】:

您需要获取提供soap_serializeheader 的库以便为共享库编译准备好,而不是ebaySoaLibClientLib.cpp。使用g++ -v 查看g++ 正在使用哪些库。尝试使用共享库而不是静态库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-17
    • 2021-05-17
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 2020-01-17
    • 2016-06-06
    相关资源
    最近更新 更多