![](/img/trans.png)
[英]Linker error: “relocation R_X86_64_PC32 against symbol `xmlFree' … recompile with -fPIC” but offending library was already compiled with -fPIC
[英]linker error “relocation R_X86_64_PC32 against undefined symbol” despite compilation with -fPIC
我正在使用命令行編譯一個c ++程序
g++ -c prog.cc -std=c++11 -march=native -fPIC -fopenmp
然后嘗試通過創建共享對象
g++ prog.o -shared -fopenmp -o lib/libprog.so
這一直都有效。 但今天我得到:
/usr/bin/ld: prog.o: relocation R_X86_64_PC32 against undefined symbol
`_ZTVN12_GLOBAL__N_111handle_baseE' 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
符號_ZTVN12_GLOBAL__N_111handle_baseE
de- _ZTVN12_GLOBAL__N_111handle_baseE
to vtable for (anonymous namespace)::handle_base
( handle_base
是handle_base
中匿名命名空間中定義的多態類,是的,我調用dynamic_cast<handle_base>()
。)
我正在使用gcc版本4.7.0(GCC)和GNU ld(GNU Binutils; openSUSE 11.1)2.19。 任何人都可以提供幫助(建議解決方案[除了沒有共享對象或dynamic cast
])?
升級到ubuntu 14.04時,我遇到了類似的問題。 我不得不在定義“缺失”符號的源文件中添加-fkeep-inline-functions。 不知道你的問題是否相似。
您只需要為基類隱藏默認可見性(handle_base)。 你可以這樣做 -
#define VISIBILITY __attribute__((visibility("hidden")))
class VISIBILITY handle_base;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.