1 msggt-c-pragma.h:46: parse error before `__attribu...
2 msgHow to control the gcc's output format?
1 msg[VASTU BULLETIN VOLUME-29]
1 msgStrange code generation by x86_64-pc-linux-gnu

linker problem
\ Javier Cuevas (25 Apr 2006)
. \ John Love-Jensen (25 Apr 2006)
. . \ Perry Smith (25 Apr 2006)
. \ joe_squid (16 Sep 2006)
. . \ Ravishankar S (17 Sep 2006)

5 msgJava AWT and Swing support of GCJ
1 msgHow could I get the gomp-20050608-branch source...
5 msgabout f77/f90 and gcc
1 msgVIS support in GCC for SPARC
1 msgCompilation problems on Fedora Core 5 and GCC 4.1
1 msgLionel Roux/Marnes/FR/BIO-RAD est absent(e). Li...
3 msgProblem about ccl.
2 msgA question about a MACRO,EXPORT_SYMBOL
1 msglibmudflap build or configuration problems
2 msgbinary compatibility between g++ 3.3.1 and 3.4....
3 msgRe: Undefined References while linking with wea...
2 msgProblem with virtual const
17 msgRe: Fwd: error in variable dereferencing
4 msgcompile issue - newbie
1 msgTry to build shared library Solaris x86, but '-...
Subject:linker problem
Group:Gcc-help
From:Javier Cuevas
Date:25 Apr 2006


Hi all,

I'm developing an application that uses a modular design in C++. The modular
design allows to the developers to add functionality to the main application
just adding libraries.

The library concept it's very similar to the plugins concept. Each library
is a separate project that creates a static library "libXXX.a" that includes
all ".o" modules for the library. There is a main project that call a well
know function in each library to initialize it. During the initialization
the library creates all the functionality that it provides. Mainly that's
the application design.

So, I'm having strange link behaviors when a class is defined in a library
and it is used in another library.

If we define a class A in classA.cpp file that creates the classA.o compiled
module that belongs to libA.a library...

...and...

...we define a class B t in classB.cpp file that creates the classB.o
compiled module that belongs to libB.a library.
We define a function InitLibraryB( void ) that creates an instance of classB
within initlibrary.cpp that creates initlibrary.o that belongs to libB.a
library.

Then we have a main.cpp file that contains the main function that
indirectely creates an instace of class B calling the "IniLibraryB"
function.

Then If I try to link the application using

"g++ -o main main.cpp libA.a libB.a" then the linker finds a problem looking
for the class A method implementations.

But if instead of using "g++ -o main main.cpp libA.a libB.a" I use " g++ -o
main main.cpp libA.a libB.a classA.o" the linker successfully links the
application.

Another way to get the application linked is to simulate the use the class A
in the main module(1) or using class A inside the libA.a library.(2)

- Example for (1): If I create in main.cpp an if clause that never enters
but the condition is written in a way that the compiler can't optimize it
then "g++ -o main main.cpp libA.a libB.a" links the application.

int main( int argn, char **argc )
{
if( argn==-123 ) // We have never enter in the if statement
{
class B; // That creates the instance
B.Init(); // we use the class in order to avoid the compiler "var not
//use" message.
}

InitLibraryA( void );
InitLibraryB( void );

return 0;
}

- Example for (2): If within the libA.a exists a function InitLibraryA that
creates a class A and this function is called from the main function from
main.cpp then "g++ -o main main.cpp libA.a libB.a" links the application.

I'm using the first workaround but I would like to understand what's wrong
and to solve the problem in a better way.

Thanks

Javier Cuevas Domingo
e-mail : javier.cuevas







© 2004-2008 readlist.com