gcc -I -L -l区别,gcc如何寻找头文件和库文件

来源:互联网 发布:微信打开淘宝客户端 编辑:程序博客网 时间:2024/05/18 02:37

gcc -I -L -l区别




我们用gcc编译程序时,可能会用到“-I”(大写i),“-L”(大写l),“-l”(小写l)等参数,下面做个记录:


例:

gcc -o hello hello.c -I /home/hello/include -L /home/hello/lib -lworld


上面这句表示在编译hello.c时:


-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动态库文件或libworld.a静态库,同时存在时候动态库优先,如果要强制链接静态库可以用-static或直接用libword.a,
gcc -o hello hello.c -I /home/hello/include -L /home/hello/lib /home/hello/lib/libworld.a
1 0