這段由於工作需要,做成鏈接庫文件給別人調用,但是隻想提供一個so文件,於是實現在so文件中鏈接.a文件,寫了一個測試程序,編譯腳本如下:
g++ -fPIC hello.cpp -c -o hello.o
ar rcs libhello.a hello.o
g++ -fPIC -shared -o libhello_s.so hello_s.cpp -L. -lhello
g++ -o main -g main.cpp -L. -lhello_s
/usr/bin/ld: ./libhello.a(hello.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
./libhello.a: could not read symbols: Bad value