Harish Tadikamalla
Harish Tadikamalla

Reputation: 47

gcc: Not able to create .so from object files

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.

Upvotes: 0

Views: 589

Answers (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.

Upvotes: 2

Related Questions