最终链接失败:输出collect2上的不可表示部分:错误:ld返回1退出状态

Shr*_*n40 2 c++ mysql linker

我在我的项目中使用这些库

\n\n\n\n

并使用编译我的项目

\n\n
g++ -std=c++1y -I ../../date main.cpp -lpthread -lsqlpp-mysql -lmysqlclient -lboost_system -ljson11\n
Run Code Online (Sandbox Code Playgroud)\n\n

直到昨天为止,每天都运行得很好。但现在我收到这个错误,

\n\n
\xe2\x94\x8c\xe2\x94\x80[shravan40@Debian] - [~/Work/algorithm] - [Fri Nov 18, 18:33]\n\xe2\x94\x94\xe2\x94\x80[$] <git:(riskProfiling*)> g++ -std=c++1y -I ../../date main.cpp -lpthread -lsqlpp-mysql -lmysqlclient -lboost_system -ljson11\n/usr/bin/ld: //usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5\' can not be used when making a shared object; recompile with -fPIC\n/usr/bin/ld: //usr/local/lib/libsqlpp-mysql.a(prepared_statement.cpp.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5\' can not be used when making a shared object; recompile with -fPIC\n/usr/bin/ld: //usr/local/lib/libsqlpp-mysql.a(char_result.cpp.o): relocation R_X86_64_32 against `.rodata\' can not be used when making a shared object; recompile with -fPIC\n/usr/bin/ld: //usr/local/lib/libsqlpp-mysql.a(bind_result.cpp.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5\' can not be used when making a shared object; recompile with -fPIC\n/usr/bin/ld: //usr/local/lib/libsqlpp-mysql.a(connection_handle.cpp.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5\' can not be used when making a shared object; recompile with -fPIC\n/usr/bin/ld: final link failed: Nonrepresentable section on output\ncollect2: error: ld returned 1 exit status\n\xe2\x94\x8c\xe2\x94\x80[shravan40@Debian] - [~/Work/algorithm] - [Fri Nov 18, 18:53]\n\xe2\x94\x94\xe2\x94\x80[$] <git:(riskProfiling*)> \n
Run Code Online (Sandbox Code Playgroud)\n

Shr*_*n40 5

最后,我找到了解决方案。

原来是版本的问题g++。最近的版本g++-5g++-6这样的问题,但是当我回到旧g++版本时4.9.2,一切都运行顺利。

  • 谢谢,这有效。升级到 Ubuntu 版本 17 后我遇到了这个问题。使用 -fPIC 编译没有帮助。您是否找到了一种无需使用较旧的 g++ 版本即可解决此问题的方法? (2认同)