gcc 链接库文件的方式:
1:直接在编译选项后加上库文件的绝对地址:
$ gcc -Wall calc.c /usr/lib/libm.a -o calc

2:通过 -l 选项:
$ gcc -Wall calc.c -lm -o calc

链接库文件时,可以通过 -L 选项指定库文件的路径;

Following the standard Unix convention for search paths, several directories can be specified together in an environment variable as a colon separated list;

Whenever a static library ‘libNAME.a’ would be used for linking with the option ‘-lNAME’ the compiler first checks for an alternative shared library with the same name and a ‘.so’ extension.

(注:链接多个库文件时,库文件的顺序对链接是有影响的;库文件的搜索顺序从左至右 直到搜索到对应的函数为止)

reference: man gcc (查看其中的 -llibrary 选项)

posted on 2013-02-21 17:14  bo-study  阅读(529)  评论(0编辑  收藏  举报