This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Compiling a shared lib problems
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Marcus Clyne <bu dot eugaia at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Fri, 12 Feb 2010 05:47:14 -0800
- Subject: Re: Compiling a shared lib problems
- References: <4B74F2B3.6070805@gmail.com>
On Thu, Feb 11, 2010 at 10:18 PM, Marcus Clyne <bu.eugaia@gmail.com> wrote:
> Hi,
>
> note : I've sent this to the GCC mailing list, but since I think it's
> related to ld options, I've also posted it here.
>
> I'm trying to compile a shared library, but am having problems.
>
> I have one main binary, which will load one or several shared libraries that
> all use a common set of functions. ?The functions common to all the shared
> libraries I would like to store either in another shared library, which the
> shared libraries themselves load, or (preferably) in the main binary itself.
>
> I'm using the following commands for compilation (simplified):
>
> [1] gcc -Wall -fPIC -o shared.o -c file.c
> [2] gcc -shared -o shared.so shared.o
>
> The error message I'm getting is:
>
> shared.o: relocation R_X86_64_PC32 against undefined symbol `my_func' can
> not be used when making a shared object; recompile with -fPIC
> /usr/bin/ld: final link failed: Bad value
> collect2: ld returned 1 exit status
>
> Can anyone tell me where I'm going wrong and what I need to do? ?I feel like
> I need to add something extra in the linking stage, but I'm not sure what.
>
Show me your file.c.
--
H.J.