如何生成.so和.a文件及使用

来源:互联网 发布:mac excel 提取数据 编辑:程序博客网 时间:2024/05/20 23:33

1).so文件
  g++ test_a.cpp test_b.cpp -fPIC -shared -o libtest.so # test_*.cpp 为原文件
 2).a文件
  gcc -c test_a.cpp
  gcc -c test_b.cpp
  ar -r libtest.a test_a.o test_b.o
 3) 采用动态库连接
  g++ test.cpp -o test -L. -ltest
  执行
  export LD_LIBRARY_PATH=./
  ./test
 4) 采用静态库编译
  g++ -static -o test -L. -ltest test.cpp