Unix Programming - Linking problem

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2005 > Linking problem





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Linking problem
Ulrich Hobelmann

2005-07-30, 5:50 pm

I have a simple static library, and a directory containing a test
program (on Mac OS X).

The make run is as follows:
make libfoo.a
cc -W -Wall -O2 -c -o messagebuffer.o messagebuffer.c
libtool -static -o libfoo.a messagebuffer.o
cd test; make test
cc -W -Wall -O2 -I.. -c -o main.o main.c
main.c: In function `main':
main.c:5: warning: unused variable `mb'
cc -W -Wall -o test ../libfoo.a main.o
ld: Undefined symbols:
_newMessageBuffer
make[1]: *** [test] Error 1
make: *** [test] Error 2

So libfoo.a DOES contain newMessageBuffer, because that function
is defined in messagebuffer.[ch], and disassembly shows that's
indeed there.

Even "cc -o bla libfoo.a test/main.o" gives the same ld error.
Any ideas?

--
XML is a prime example of retarded innovation.
-- Erik Meijer and Peter Drayton, Microsoft Corporation
Ulrich Hobelmann

2005-07-30, 5:50 pm

Ulrich Hobelmann wrote:
> I have a simple static library, and a directory containing a test
> program (on Mac OS X).
>
> The make run is as follows:
> make libfoo.a
> cc -W -Wall -O2 -c -o messagebuffer.o messagebuffer.c
> libtool -static -o libfoo.a messagebuffer.o
> cd test; make test
> cc -W -Wall -O2 -I.. -c -o main.o main.c
> main.c: In function `main':
> main.c:5: warning: unused variable `mb'
> cc -W -Wall -o test ../libfoo.a main.o

^ That was probably wrong, but the following doesn't work either:

cc -W -Wall -L.. -o test -lfoo main.o
ld: Undefined symbols:
_newMessageBuffer
make[1]: *** [test] Error 1
make: *** [test] Error 2

--
XML is a prime example of retarded innovation.
-- Erik Meijer and Peter Drayton, Microsoft Corporation
Paul Pluzhnikov

2005-07-30, 5:50 pm

Ulrich Hobelmann <u.hobelmann@web.de> writes:

> Even "cc -o bla libfoo.a test/main.o" gives the same ld error. Any
> ideas?


Both of your link lines are incorrect. The correct link line is:

cc -W -Wall -o test main.o ../libfoo.a

Explanation:
http://webpages.charter.net/ppluzhnikov/linker.html

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Ulrich Hobelmann

2005-07-30, 5:50 pm

Paul Pluzhnikov wrote:
> Ulrich Hobelmann <u.hobelmann@web.de> writes:
>
>
> Both of your link lines are incorrect. The correct link line is:
>
> cc -W -Wall -o test main.o ../libfoo.a
>
> Explanation:
> http://webpages.charter.net/ppluzhnikov/linker.html


That works, thanks! Funny though that I don't need a -l, because
that's what I'm used to from dynamic stuff...

--
XML is a prime example of retarded innovation.
-- Erik Meijer and Peter Drayton, Microsoft Corporation
Matthias Buelow

2005-07-31, 5:55 pm

Ulrich Hobelmann <u.hobelmann@web.de> writes:

>That works, thanks! Funny though that I don't need a -l, because
>that's what I'm used to from dynamic stuff...


You can do that but then you must put the -lfoo _after_ the object
file that references symbols from it since the linker resolves symbols
from the left to the right (in order as given on the command-line).
That's also the same with dynamic libraries, afaik.

mkb.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com