Link the static library in gcc without specifying the prefix 'lib'

According to this question, the gcc -l requires your library to be called libXXX.a.

Is there a way to link a static library using another command with gcc? The goal is to avoid this lib prefix.

+6
source share
2 answers

Just pass the library as in the source file:

 gcc main.c yourlibrary.a -o prog 
+6
source

As nunzio said. Just pass it directly as input file. He beat me, but here is a complete example.

mylib.c:

 #include <stdio.h> void say_hi(void) { printf("hi\n"); } 

main.c:

 extern void say_hi(void); int main(int argc, char**argv) { say_hi(); return 0; } 

Makefile:

 main: main.c mylib.a gcc -o main main.c mylib.a mylib.a: mylib.o ar rcs mylib.a mylib.o mylib.o: mylib.c gcc -c -o $@ $^ 

I understand that this implies some basic knowledge in Make. To do the same without make, run the following commands:

 gcc -c -o mylib.o mylib.c ar rcs mylib.a mylib.o gcc -o main main.c mylib.a 
+5
source

All Articles