问题解决
- 提示错误
$ cc -shared -o libex29.so libex29.o
/usr/bin/ld: libex29.o: relocation R_X86_64_32 against `.rodata'
can not be used when making a shared object;
recompile with -fPIC
libex29.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
-
解决方法 : 添加
-fPIC
参数
$ cc -fPIC -c libex29.c -o libex29.o
$ cc -shared -o libex29.so libex29.o
$ ls
dbg.h ex29.c libex29.c libex29.o libex29.so
参考资料
- Linux共享对象之编译参数fPIC
https://www.cnblogs.com/cswuyg/p/3830703.html
网友评论