This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

g++ isn't link an indirectly used .a library


At the moment, my C++ project has two libraries (which I'll refer to
as liba and libb) and one bin application (which I'll refer to as
app). I created the project in KDevelop as an empty Autotools Template
Automake Project.

I pust this question in the kdevelop forums, but they said the proper
place would be with g++ -- since kdevelop shows exactly what it's
giving g++ as arguments.  Any help would be much appreciated!

app requires liba. liba requires libb. At the moment, app only
requires libb because it requires liba -- app only indirectly needs
libb. That is, if lib didn't use liba, it wouldn't need libb to be
linked.

I'm not sure if this is an issue with my KDevelop settings, or rather
if it is a g++ problem. If it's a g++ problem, I'm wondering if
there's a way I can force g++ to really link what KDevelop appears to
be telling it to link.

When I right click my application and select Build Target, I get the
following error:

g++ -g -O2 -o app app.o -L/usr/lib/mysql ../../liba/liba.a
../../libb/libb.a -lmysqlclient
../../liba/liba.a(liba.o): In function `@@@`:
liba.cpp:@: undefined reference to `libb::@@@`
collect2: ld returned 1 exit status

KDevelopp appears to be telling g++ to link in both liba.a and libb.a,
however it appears g++ isn't linking in libb.a.

If I change app's main() from:
libAClass goingToUseThis();

to:
libBClass hack();
libAClass goingToUseThis();

Then it links fine.


Is there a way for me to forces g++ to actually link libb.a, when app
is only directly using liba.a? I'm suprised g++ can't figure out that
libb.a really has to be linked since it's being told to do so through
the arguments given.  Then again, maybe I'm missing something
simple...


I'm using versions all included in the default RHEL5 yum repositories.
KDevelop 3.5.1, g++ 4.1.2, automake 1.9.6, autoconf 2.59.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]