Emb Prg
Emb Prg

Reputation: 43

How to add a custom library to GCC while compliling?

i have downloaded a C library from the net with the name libsal.a, to access the APIs in that library i include a header file by name #include in my main.c. i use the following command to compile it :

gcc -L /home/traana/Desktop/opensal-1.0.0/libsal.a main.c

but get the following error when i compile

main.c:3:17: fatal error: sal.h: No such file or directory
compilation terminated.

How do I do this correctly?

Upvotes: 4

Views: 21608

Answers (3)

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81684

When compiling your source, it's not the library, but the include files that are relevant; so you'll need to tell gcc where those are, something like

gcc -c -I/home/traana/Desktop/opensal-1.0.0/include main.c

and then link the application with something like

gcc -L/home/traana/Desktop/opensal-1.0.0 -lsal main.o 

Upvotes: 9

Barton Chittenden
Barton Chittenden

Reputation: 4416

I believe that there are three arguments that you will need to set:

-I <include directory>
-L <library directory>
-l <library name>

The include directory will be location of the header files. The library directory will be the location of the library (.a or .so), and the library name will be the name of the library file, without the leading 'lib' prefix or its extension (i.e. -lsal rather than -l libsal.a ).

Upvotes: 12

Pierre
Pierre

Reputation: 35236

if the *.h are in /home/traana/Desktop/opensal-1.0.0

try

 gcc -I /home/traana/Desktop/opensal-1.0.0 -L /home/traana/Desktop/opensal-1.0.0 main.c -lsal

Upvotes: 0

Related Questions