* static library and undefined reference
@ 2004-04-09 2:45 Iker Arizmendi
2004-04-09 3:28 ` Iker Arizmendi
2004-04-09 13:17 ` Eljay Love-Jensen
0 siblings, 2 replies; 4+ messages in thread
From: Iker Arizmendi @ 2004-04-09 2:45 UTC (permalink / raw)
To: gcc-help
Hello all.
I have a project that creates several static libraries
in two directories and an executable that uses them in
a third. The libraries build just fine, and the
executable builds fine, but fails during linking with
"undefined reference" errors. I've checked the libraries
with nm and can see that the symbols the linker claims
are undefined are exported (nm shows marks them with
a "T"). I've checked that the link line includes the
libraries and that libraries that are depended on by
other libraries appear first (and before the executable's
.o file). I also made sure that all the files involved
were compiled with g++ and not gcc. But the errors persist.
What am I missing here? Any help greatly appreciated.
Regards,
Iker
--
Iker Arizmendi
AT&T Labs - Research
Speech and Image Processing Lab
e: iker@research.att.com
w: http://research.att.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: static library and undefined reference
2004-04-09 2:45 static library and undefined reference Iker Arizmendi
@ 2004-04-09 3:28 ` Iker Arizmendi
2004-04-09 3:46 ` Iker Arizmendi
2004-04-09 13:17 ` Eljay Love-Jensen
1 sibling, 1 reply; 4+ messages in thread
From: Iker Arizmendi @ 2004-04-09 3:28 UTC (permalink / raw)
To: Iker Arizmendi; +Cc: gcc-help
Just a quick follow up - when I put the static libraries
_after_ the executable's .o file I get _more_ undefined
reference errors.
Iker
Iker Arizmendi wrote:
> Hello all.
>
> I have a project that creates several static libraries
> in two directories and an executable that uses them in
> a third. The libraries build just fine, and the
> executable builds fine, but fails during linking with
> "undefined reference" errors. I've checked the libraries
> with nm and can see that the symbols the linker claims
> are undefined are exported (nm shows marks them with
> a "T"). I've checked that the link line includes the
> libraries and that libraries that are depended on by
> other libraries appear first (and before the executable's
> .o file). I also made sure that all the files involved
> were compiled with g++ and not gcc. But the errors persist.
>
> What am I missing here? Any help greatly appreciated.
>
> Regards,
> Iker
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: static library and undefined reference
2004-04-09 3:28 ` Iker Arizmendi
@ 2004-04-09 3:46 ` Iker Arizmendi
0 siblings, 0 replies; 4+ messages in thread
From: Iker Arizmendi @ 2004-04-09 3:46 UTC (permalink / raw)
To: Iker Arizmendi; +Cc: gcc-help
After reading a helpful post on the topic which describes
that linker will "throw away" a library if it comes across
it but none of the symbols it defines are needed, I realized
that my link line was wrong. The problem was not between
my executable and my library but between my two libraries.
I had placed the "depended on" library first thinking that
the symbols should be available when they were needed (which
explains why I got errors when my executable's .o was placed
before or after the libraries).
Regards,
Iker
Iker Arizmendi wrote:
> Just a quick follow up - when I put the static libraries
> _after_ the executable's .o file I get _more_ undefined
> reference errors.
>
> Iker
>
>
> Iker Arizmendi wrote:
>
>> Hello all.
>>
>> I have a project that creates several static libraries
>> in two directories and an executable that uses them in
>> a third. The libraries build just fine, and the
>> executable builds fine, but fails during linking with
>> "undefined reference" errors. I've checked the libraries
>> with nm and can see that the symbols the linker claims
>> are undefined are exported (nm shows marks them with
>> a "T"). I've checked that the link line includes the
>> libraries and that libraries that are depended on by
>> other libraries appear first (and before the executable's
>> .o file). I also made sure that all the files involved
>> were compiled with g++ and not gcc. But the errors persist.
>>
>> What am I missing here? Any help greatly appreciated.
>>
>> Regards,
>> Iker
>>
>>
>>
>
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: static library and undefined reference
2004-04-09 2:45 static library and undefined reference Iker Arizmendi
2004-04-09 3:28 ` Iker Arizmendi
@ 2004-04-09 13:17 ` Eljay Love-Jensen
1 sibling, 0 replies; 4+ messages in thread
From: Eljay Love-Jensen @ 2004-04-09 13:17 UTC (permalink / raw)
To: Iker Arizmendi, gcc-help
Hi Iker,
The order of the libraries on the command line is significant.
If library libfoo.a has an undefined symbol, and that symbol is in
libbar.a, you need to put libfoo.a before libbar.a on the command line.
If you have a situation where libfoo.a is dependent on libbar.a, and
libbar.a is dependent on libfoo.a, you'll need to specify them
twice: libfoo.a libbar.a libfoo.a. Generally, it's recommended that you
don't have interdependencies like that.
HTH,
--Eljay
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-04-09 13:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-09 2:45 static library and undefined reference Iker Arizmendi
2004-04-09 3:28 ` Iker Arizmendi
2004-04-09 3:46 ` Iker Arizmendi
2004-04-09 13:17 ` Eljay Love-Jensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).