.a
gcc -c test1.c test2.c(或者g++ -c test1.cpp test2.cpp )— .o
ar -r libtest.a test1.o test2.o (或者 ar rcs libtest.a test1.o test2.o) — .a
g++ -o main main.cpp -L. -ltest (或者 g++ -o main main.c libtest.a) -L. 代表当前路径
.so
gcc -fPIC -c file1.c
gcc -fPIC -c file2.c
gcc -shared libxxx.so file1.o file2.o
gcc file1.o file2.o -Lpath -lxxx -o program.exe
ldd program.exe —查看链接情况;
程序运行,先找动态库,再找静态库;
在程序运行期间,也需要告诉系统去哪里找你的动态链接库文件。在UNIX下是通过定义名为 LD_LIBRARY_PATH 的环境变量来实现的。只需将path赋值给此变量即可