求帮忙分析编译动态库的问题?

luxihua 2011-03-09 04:49:32
我平台上编译不了啊
cat hello.c
void hello()
{
}
g++ -shared hello.c -o libhello.so
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/bin/ld: /tmp/cca0uT7R.o: relocation R_X86
_64_32 against `__gxx_personality_v0' can not be used when making a shared object; recompile with -fPIC
/tmp/cca0uT7R.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
...全文
78 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
luxihua 2011-03-09
  • 打赏
  • 举报
回复
是编译成位置无关的库吗,啥意思不太明白?
luxihua 2011-03-09
  • 打赏
  • 举报
回复
那为什么不加这个就不行呢
justkk 2011-03-09
  • 打赏
  • 举报
回复
-fPIC
If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding any limit on the size of the global off-
set table. This option makes a difference on the m68k, PowerPC and SPARC.

Position-independent code requires special support, and therefore works only on certain machines.
luxihua 2011-03-09
  • 打赏
  • 举报
回复
还是谢谢呵 ,
刚不知道出什么问题了,
现在编译过了。
luxihua 2011-03-09
  • 打赏
  • 举报
回复
惭愧 刚加了-fpic,但是还是编译错了
这个区分大小写啊
太乙 2011-03-09
  • 打赏
  • 举报
回复
g++ -shared hello.c -o libhello.so -fPIC
justkk 2011-03-09
  • 打赏
  • 举报
回复
试试
g++ -fPIC -shared hello.c -o libhello.so
太乙 2011-03-09
  • 打赏
  • 举报
回复
g++ -shared hello.c -o libhello.so -fPIC

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧