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.
|