Reputation: 9175
I'm trying to make a relocatable object file with gcc. I use solution from this post. The solution works fine with ld:
$ ld -r a.o b.o -o c.o
However when I try to use it with gcc, the following error happens:
$ gcc -r a.o b.o -o c.o
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
Using the -Wl,-r
and -Wl,--relocatable
options gives the same result.
Is there any way to link relocatable object file with gcc or I'm forced to use ld for doing this?
Upvotes: 0
Views: 665
Reputation: 9175
To solve this problem, the -nostdlib
option must also be passed to gcc:
$ gcc -r -nostdlib a.o b.o -o c.o
I don't know it for sure, but it seems without this option gcc tries to link standard libraries into output relocatable object.
Upvotes: 1