64位系统下连接静态库报错:“could not read symbols: Bad value”的解决办法

公司来了新服务器(64位系统),将项目从原来的服务器(32位)上迁移过去后,编译出错:

g++     -shared -o dist/Debug/GNU-Linux-x86/libGeoFlock.so -fPIC build/Debug/GNU-Linux-x86/GeoFlock.o build/Debug/GNU-Linux-x86/library.o build/Debug/GNU-Linux-x86/GeoCrawler.o http://www.cnblogs.com/framework/jasgreen/dist/Debug/GNU-Linux-x86/libjasgreen.a 
/usr/bin/ld: http://www.cnblogs.com/framework/jasgreen/dist/Debug/GNU-Linux-x86/libjasgreen.a(properties.o): relocation R_X86_64_32 against `__gxx_personality_v0' can not be used when making a shared object; recompile with -fPIC
http://www.cnblogs.com/framework/jasgreen/dist/Debug/GNU-Linux-x86/libjasgreen.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

经分析,是我的项目引用了一个静态库:“libjasgreen.a”,在连接该库的时候出错了,提示“can not be used when making a shared object”。

解决办法为:“recompile with -fPIC”。很简单:使用 -fPIC选项重新编译一下libjasgreen.a即可。

原文地址:https://www.cnblogs.com/chutianyao/p/2582941.html