LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem in static linking in linux. (https://www.linuxquestions.org/questions/linux-newbie-8/problem-in-static-linking-in-linux-938629/)

neha l 04-07-2012 10:56 AM

Problem in static linking in linux.
 
hi all, I am learning how to create static link library and I am doing it first time.

Firstly I created two header files ctest1.h and ctest2.h and compiled them by the following commands:

gcc ctest1.h -o ctest2.out (successfully executed)
gcc ctest2.h -o ctest2.out (successfully executed)

and then making the archive file by the following command

ar rcs libctest.a ctest1.out ctest2.out (successfully executed)

and then I tried to link cprog.c with this by the following command

gcc -static cprog.c libctest.a -o cprog.out (not successfully executed)

(error: libctest.c : could not read symbols: Archive has no index; run ranlib to add one)

then I gave the following command
ranlib libctest.a
and then again the same command
gcc -static cprog.c libctest.a -o cprog.out (it gave the same error again).

Please tell me what I am doing wrong, also I am a beginner with all this, if you want to suggest anything else regarding this, then I will be happy to implement your suggestion.

Thank you so much.

Dark_Helmet 04-07-2012 11:10 AM

I don't have a lot of experience with creating static libraries, but I did come across this page once when I stumbled through the process: could not read symbols . . .

Perhaps it will help you as well.

EDIT:
Also be sure to read the exchange beneath the check-mark answer--it leads to some additional debugging.


All times are GMT -5. The time now is 08:59 AM.