2024-11-23 11:00:35 +00:00

28 lines
755 B
Plaintext

g++ -S test.s test.cpp #编译成汇编文件
g++ -c test.o test.s #目标文件
g++ -o test test.o #链接
g++ -O1/-O2/-O3 // 优化选项
#静态库制作:
g++ -c -o libtest.a {test.cpp 源代码文件清单}
// g++ -c test.cpp
// ar -crv libtest.a test.o
#动态库制作
g++ -fPIC -shared -o libtest.so {test.cpp 源代码文件清单}
// g++ -fPIC -c test.cpp
// g++ -shared -o libtest.so tset.o
两种方法
1 + .so 放到 /usr/lib 或 /lib
2 + 路径放到/etc/ld.so.conf 运行ldconfd 重建/etc/ld.so.cache
# 库使用
g++ -o main -l库名 -L库路径 -I头文件路径
// g++ -o main -ltest -L/home/e0x1a/test
如果是动态库,需要指定 LD_LIBRARY_PATH 环境变量 //待查
用 echo $LD_LIBRARY_PATH 查看