gcc: Not able to create .so from object files

青春壹個敷衍的年華 提交于 2019-12-11 16:54:42

问题


I am trying to create .so dynamic library from *.o files and facing below issue.

LOG:

[nptemp-static]$ gcc -shared *.o -o libexample.so

/usr/bin/ld: bindings_hubbub_parser.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
bindings_hubbub_parser.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

Any idea? Do I need to recompile my whole source code with the option specified?

Actually, I am not aware of the source code which I compiled because all the source code is open source which I downloaded and compiled by following instructions in README.


回答1:


I am trying to create .so dynamic library from *.o files and facing below issue.

This is not that simple. In practice, you should compile specifically when making a shared library, at least on Linux.

(Perhaps you might need to edit your Makefile or configure somehow your build automation if it was not designed for building a shared library; if building some free software library, you might ask help from its authors or community)

Shared libraries want to have position independent code. So you need to compile their source code with the -fPIC flag passed to g++ or gcc (see this). You could also want to explicit the rpath.

Read Drepper's paper: How To Write Shared Libraries.



来源:https://stackoverflow.com/questions/50094800/gcc-not-able-to-create-so-from-object-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!