help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: g++ linker error linking dependent static libraries to create execu


From: sriram . sundararajan
Subject: Re: g++ linker error linking dependent static libraries to create executable
Date: Fri, 25 Jan 2008 09:35:52 -0800 (PST)
User-agent: G2/1.0

On Jan 25, 1:45 am, Bernd Strieder <strie...@informatik.uni-kl.de>
wrote:
> Hello,
>
> sriram.sundarara...@gmail.com wrote:
> > I'm battling a linker issue. Here is the scenario. I have two static
> > libraries libA.a and libB.b and am trying to create an executable
> > hello.exe from hello.cpp, libA.a and libB.a.
> > g++ -W -Wall -pipe -g -o main.exe main.o  -Lblah/src -Lblah/lib1 -
> > Lblah/lib2 blah/lib1/libA.a blah/lib2/libB.a
>
> > I got this....
>
> > blah/lib2/libB.a(libB.o): In function `ZN1B1aESs':
> > blah/lib2/libB.cpp:9: undefined reference to `A::printB(std::string)'
> > blah/lib2/libB.a(libB.o): In function `ZN1B1bEi':
> > blah/lib2/libB.cpp:15: undefined reference to `A::printA(int)'
>
> libB depends on libA, so libA should go after libB in the command line,
Yup that worked! Thanks

> or you have to use the --start-group --end-group options. The GNU
> linker (and possibly most other linkers) treats all linked files in the
> command-line in the order they are given, not returning to an earlier
> one automatically. In your case you might get away most easily by
> linking libA once before libB and again after it.
Just linking libA after libB worked.

> It is generally best to avoid circular references, since it is prone to
> errors and whatever you do, it adds overhead to the linking process.

Thanks! I'll keep that in mind.

Sriram


reply via email to

[Prev in Thread] Current Thread [Next in Thread]