LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Linking program with .a libraries (http://www.linuxquestions.org/questions/programming-9/linking-program-with-a-libraries-315717/)

rudy2 04-21-2005 12:08 PM

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 02: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 06: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 10:15 AM.