linux .o,.a,.so
- .o,是目标文件,相当于windows中的.obj文件
- .so 为共享库,是shared object,用于动态连接的,相当于windows下的dll
- .a为静态库,是好多个.o合在一起,用于静态连接
gcc -o -I[],-L[],-lword
例子:
gcc -o hello hello.c -I /home/hello/include -L /home/hello/lib -lworld
参数说明:
-
-I /home/hello/include表示将/home/hello/include目录作为第一个寻找头文件的目录,寻找的顺序是:/home/hello/include–>/usr/include–>/usr/local/include
-
-L /home/hello/lib表示将/home/hello/lib目录作为第一个寻找库文件的目录,寻找的顺序是:/home/hello/lib–>/lib–>/usr/lib–>/usr/local/lib
-
-lworld表示在上面的lib的路径中寻找libworld.so动态库文件
问题
问题1:-l链接的是动态库还是静态库?
答案:如果同时都有.so和.a 那么优先链接.so
问题2:如果同时有动态库和静态库如何链接静态库?
答案:使用显示链接 gcc -l:lib***.a 或者在gcc编译时加入参数-static -lxxx