链接器错误“针对未定义符号重定位R_X86_64_PC32”尽管与-fPIC汇编 [英] linker error "relocation R_X86_64_PC32 against undefined symbol" despite compilation with -fPIC

查看:2421
本文介绍了链接器错误“针对未定义符号重定位R_X86_64_PC32”尽管与-fPIC汇编的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用命令行编译c ++程序

  g ++ -c prog.cc -std = c ++ 11 -march = native -fPIC -fopenmp 

然后尝试通过

  g ++ prog.o -shared -fopenmp -o lib / libprog.so 

这一直奏效。但是今天我得到了:

$ p $ / usr / bin / ld:prog.o:relocation R_X86_64_PC32针对未定义符号
` _ZTVN12_GLOBAL__N_111handle_baseE'在制作共享
对象时不能使用;使用-fPIC
重新编译/ usr / bin / ld:最终链接失败:错误值
collect2:错误:ld返回1退出状态
_ZTVN12_GLOBAL__N_111handle_baseE 对
vtable进行解压缩:
> :handle_base

handle_base 是prog.cc中匿名命名空间中定义的多态类,是的,我调用 dynamic_cast< handle_base>()。)



我使用gcc版本4.7.0(GCC)和GNU ld(GNU Binutils ; openSUSE 11.1)2.19。任何人都可以帮助(建议解决方案[除了没有共享对象或动态转换])之外)?


方案

升级到Ubuntu 14.04时,我遇到了类似的情况。我必须在定义'缺少'符号的源文件中添加-fkeep-inline-functions。不知道你的问题是否相似。


I'm compiling a c++ program using the command line

g++ -c prog.cc -std=c++11 -march=native -fPIC -fopenmp

and then try to make a shared object via

g++ prog.o -shared -fopenmp -o lib/libprog.so

This has always worked. But today I get:

/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

The symbol _ZTVN12_GLOBAL__N_111handle_baseE de-mangles to vtable for (anonymous namespace)::handle_base (handle_base is a polymorphic class defined in the anonymous namespace in prog.cc and yes I do call dynamic_cast<handle_base>().)

I'm using gcc version 4.7.0 (GCC) and GNU ld (GNU Binutils; openSUSE 11.1) 2.19. Can anybody help (suggest solutions [other than doing without shared object or the dynamic cast])?

解决方案

I just ran into something similar when upgrading to ubuntu 14.04. I had to add -fkeep-inline-functions to the source file that defined the 'missing' symbol. No idea if your problem is similar.

这篇关于链接器错误“针对未定义符号重定位R_X86_64_PC32”尽管与-fPIC汇编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆