簡體   English   中英

鏈接器錯誤“重定位R_X86_64_PC32對未定義的符號”盡管使用-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_basehandle_basehandle_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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM