这段由于工作需要,做成链接库文件给别人调用,但是只想提供一个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