gcc linkage problems

D

Dave Joseph

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

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.

Some of the unresolved linkage errors are marked as [in-charge] others
as [not in-charge], I don't know what this means.

I am using gcc 3.2.1 and ld 2.11.90.0.8
 
R

Rolf Magnus

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

Dave said:
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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top