Re: gcc linkage problems

From: Rolf Magnus (ramagnus_at_t-online.de)
Date: 10/06/03


Date: Mon, 06 Oct 2003 13:33:37 +0200

xpost and f'up2 gnu.g++.help, since that question is off-topic here.

Dave Joseph wrote:

> I'm trying to link with a static library and keep getting undefined
> references to symbols that are defined in the library. The library is
> called libmwunit.a and is located in /app/tp/mw/lib, I'm using the
> following link step:
>
> g++ -o target -static -L/app/tp/mw/lib -lmwunit TestConsumer.o
> TestApp.o

The order matters. With your command line, the linker first opens
libmwunit, but doesn't find any symbol there that it needs. So it
unloads that library and goes on. Then TestConsumer and TestApp are
linked, using some symbols that are not defined there. The linker
remembers them as unresolved and goes on, but since there is nothing
afterward, those symbols stay unresolved.

Try:

g++ -o target -static -L/app/tp/mw/lib TestConsumer.o TestApp.o -lmwunit

giving the linker a chance to use the lib to resolve the missing symbols
from your .o files.

> TestApp.o and TestConsumer.o are part of my test harness and target is
> the executable I am trying to produce. I have extracted objects from
> the archive to check that the symbols exist – they do – and I can link
> directly with them. I've also tried various other combinations of
> ordering for libraries objects with and without the static specifier.

Probably you didn't try the right one :)



Relevant Pages

  • Re: calling my custom function same as library function
    ... > malloc() is placed between their other object files and the ... > right such as the other libraries. ... > unsatisfied references to the left of the current object. ... I think you are confused about the linker action. ...
    (comp.lang.c)
  • RE: unresolved symbols __eqd, __negd, __itod etc while building platform
    ... The __imp_ prefixes are references to the import table that the linker ... exported by various libraries like corecrt.lib, ...
    (microsoft.public.windowsce.embedded)
  • Re: Defining many classes in a single file
    ... And one can declare just as many in a header file. ... Another reason for one class one file is due to linker ... smallest resolution. ... In this case, you can have libraries. ...
    (comp.lang.cpp)
  • FreeBSD 5.1 BETA 2 make cvsup-without-gui fails
    ... checking if the linker is GNU ld... ... checking whether the linker supports shared libraries... ... checking if libtool supports shared libraries... ...
    (freebsd-current)
  • Re: strange linking problem
    ... I usually use C, and since strings ... the linker goes through the object ... files and looks for unsatisfied references to functions and variables. ... references by linking code from the libraries into the executable. ...
    (comp.lang.fortran)