1. 程式人生 > >cmake編譯靜態庫/動態庫/可執行檔案及測試demo

cmake編譯靜態庫/動態庫/可執行檔案及測試demo

0.編譯
# cd build
# cmake ..
# make -j4
//test.c測試demo
#include <stdio.h>
 int main(){
  HelloFunc();
}
1.呼叫so動態庫
<1>.方法一
# export LD_LIBRARY_PATH=/home/ubuntu/test/cmake_shared_demo/build/lib:$LD_LIBRARY_PATH
# gcc test.c -o test -L ./ -lhello
# ./test
<2>.方法二
# sudo cp libhello.so /usr/lib
# ./test
2.呼叫靜態庫
# gcc test.c -o test ./libhello.a

# ./test