-   Programming (
-   -   Linking program with .a libraries (

rudy2 04-21-2005 11:08 AM

Linking program with .a libraries
I am busy porting some old c code from IBM AIX to Linux. It's the first time I use Linux so I guess I am an absolute newbie .

The code is compiled with -c -g and then the .o files are stored by module in a module.a library (ar rcv). The main() function is also located in one of the module.a libraries.

The compilation works fine (same script as with AIX), but when I use the link command:

cc module1.a module2.a .... modulen.a -o myprogram

then it complains about undefined references in functions of module1.a using e.g. functions of module2.a. Declairing the function as external in module1.a and recompile does not help.

The same command under IBM AIX works perfect and links the program without complaining.

Is there a compiler or linker option I should use?

Harmaa Kettu 04-21-2005 01:38 PM

This one reminds me of my first experiments with gcc in 1998 or -99. :)

The solution is still in the same place.

rudy2 04-22-2005 05:36 AM

Thanks, grouping the libraries solved the problem! Below a sample command so another newbie might not struggle with the syntax as I did.

gcc -Wl,--start-group \
../../lib/boot.a \
../../lib/def.a \
../../lib/cmn.a \
../../lib/dde.a \
-Wl,--end-group \
-o ../../run/boot

All times are GMT -5. The time now is 06:11 PM.