I'm linking *.a file with *.c file, so I have used the following command:

gcc abc.c -l ad.a

(here abc is the C source file and ad is the static library file)

then after executing the following error message is coming. the library lad.a not found.

  • 1
    With static libraries you don't need to use -l. Try gcc abc.c libad.a, or whatever the actual static library name is. Just pretend the library is another object file. – jw013 Oct 13 '14 at 2:33
  • Otherwise, remove the extension and add the directory: gcc abc.c -L . -lad – o11c Oct 13 '14 at 2:51
  • I don't see any option of ANSI: gcc -ansi -Wpedantic -std=c++11 , of course you can choose another std. – PersianGulf Oct 13 '14 at 2:54

To link with a library with a filename libad.a you link options to gcc should be:

gcc abc.c -lad 

So you don't specify the extension, nor the starting lib part of the library file name. The output file will be a.out. You can specify extra search paths for the library with -L:

gcc abc.c -L path_to_directory -lad 
  • i tried with these, but the following error is coming.library -lad not found.fatal:id:not found.collect2: some error came , i don't remember exactly – user87627 Oct 13 '14 at 17:14
  • 1
    @user87627 Where is the file libad.a, try to copy in the exact message. Without that it is just guesswork what might be wrong. – Anthon Oct 13 '14 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.