This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Troubles linking with ld


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

OK, I'll resist the temptation to ask numerous questions about why
I can't use ld here and just go with your suggestion...

Now when I try to use gcc to compile and link my shared library, I
get the following:


gcc -m64 -c -Wall -fPIC -g -o file5.o file5.c

gcc -shared -Wl,--whole-archive -fPIC -o libnew.so file5.o
libfiles12.a libfiles34.a

/usr/lib/gcc/x86_64-redhat-
linux/3.4.4/libgcc.a(_muldi3.oS)(.text+0x0): In function `__multi3':
: multiple definition of `__multi3'
/usr/lib/gcc/x86_64-redhat-
linux/3.4.4/libgcc.a(_muldi3.oS)(.text+0x0): first defined here

::

/usr/lib/gcc/x86_64-redhat-
linux/3.4.4/libgcc.a(__gcc_bcmp.oS)(.text+0x0): In function
`__gcc_bcmp':
: multiple definition of `__gcc_bcmp'
/usr/lib/gcc/x86_64-redhat-
linux/3.4.4/libgcc.a(__gcc_bcmp.oS)(.text+0x0): first defined here

/usr/lib64/libc_nonshared.a(elf-init.oS)(.text+0xd): In function
`__libc_csu_init':
: undefined reference to `__init_array_start'
/usr/bin/ld: /usr/lib64/libc_nonshared.a(elf-init.oS): relocation
R_X86_64_PC32 against `__init_array_start' 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
make[1]: *** [libnew.so] Error 1

Sorry, this is kind of messy but I did chop it down for you.

Am I missing gcc flags?



On Tue, 07 Feb 2006 17:25:04 -0500 Daniel Jacobowitz
<drow@false.org> wrote:
>On Tue, Feb 07, 2006 at 05:19:51PM -0500, securehell@hushmail.com
>wrote:
>> ld -shared --whole-archive -o libnew.so file5.o libfiles12.a
>> libfiles34.a
>
>Don't.  Use gcc -shared instead; it knows how to invoke ld
>correctly
>to link shared libraries.
>
>> gcc -m64 -c -Wall -fPIC -g -o main.o main.cpp
>> ld -lc -o main main.o libnew.so
>> /usr/bin/ld: warning: cannot find entry symbol _start;
>defaulting
>> to 00000000004010a0
>> main.o(.gnu.linkonce.d.DW.ref.__gxx_personality_v0+0x0):
>undefined
>> reference to `__gxx_personality_v0'
>> libnew.so: undefined reference to `fstat'
>
>Especially true for executables.  And in this case, you need to
>link
>with g++, not gcc.
>
>--
>Daniel Jacobowitz
>CodeSourcery
-----BEGIN PGP SIGNATURE-----
Note: This signature can be verified at https://www.hushtools.com/verify
Version: Hush 2.4

wkYEARECAAYFAkPpJqAACgkQRBFe1uc9INqp/gCgmTP/p0V9W61xROUqjWXrmbiPgKIA
nAjFzKC4jo5OvgLwx/8WcaggEbze
=rpnQ
-----END PGP SIGNATURE-----



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]