-fPIC -shared
生成动态链接库 .so
ar rc
生成静态连接库 .a
参数:“-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动态库文件(如果gcc编译选项中加入了“-static”表示寻找libworld.a静态库文件)
关于 -pthread
和-lpthread
$ man gcc | grep pthread
-mvxworks -G num -pthread
-mno-unaligned-doubles -mv8plus -mno-v8plus -mvis -mno-vis -threads -pthreads
-pthread
implies -pthread, and thus is only supported on targets that have support for
-pthread.
implies -pthread, and thus is only supported on targets that have support for
-pthread.
option and the -pthread option are incompatible.
-pthread
Adds support for multithreading with the pthreads library. This option sets flags for
-pthreads
-pthread
This is a synonym for -pthreads.
$ man gcc | grep lpthread
$
gcc 4.5.2中已经没有了关于 -lpthread的介绍了。所以以后的多线程编译应该用-pthread,而不是-lpthread。