You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu下Hazelcast C++客户端编译失败求助

解决Hazelcast C++客户端编译时的PIE重定位错误

这个问题是因为现代Linux发行版的GCC默认会生成位置独立可执行文件(PIE),但你链接的Hazelcast静态库是没有用-fPIC编译的,两者不兼容导致了重定位错误。下面是两种解决方法:

快速解决:关闭PIE生成

直接在你的编译命令中添加-no-pie选项,告诉编译器不要生成PIE可执行文件,这样就能和非PIC的静态库正常链接了。修改后的完整命令:

g++ FillMap.cpp -w -pthread -no-pie -Icpp/Linux_64/external/include -Icpp/Linux_64/hazelcast/include -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS /home/myubuntu/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a

更规范的方案:重新编译带-fPIC的Hazelcast库

如果你希望保持PIE的安全特性,可以重新编译Hazelcast C++客户端的静态库,编译过程中添加-fPIC编译选项,生成位置无关的代码。不过这个步骤相对繁琐,适合需要长期维护的项目。


你提供的原始编译命令:

g++ FillMap.cpp -w -pthread -Icpp/Linux_64/external/include -Icpp/Linux_64/hazelcast/include -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS /home/myubuntu/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a

原始错误信息:

/usr/bin/ld: /home/radkathimar/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a(NearCacheStatsImpl.cpp.o): relocation R_X86_64_32S against symbol _ZTVN9hazelcast6client7monitor4impl18NearCacheStatsImplE' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/radkathimar/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a(LocalMapStatsImpl.cpp.o): relocation R_X86_64_32S against symbol _ZTVN9hazelcast6client7monitor4impl17LocalMapStatsImplE' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/radkathimar/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a(HazelcastClient.cpp.o): relocation R_X86_64_32S against symbol _ZTVN5boost6detail17sp_counted_impl_pIN9hazelcast6client4impl27HazelcastClientInstanceImplEEE' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/radkathimar/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a(KeyStateMarkerImpl.cpp.o): relocation R_X86_64_32S against symbol _ZTVN9hazelcast6client8internal9nearcache4impl18KeyStateMarkerImplE' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/radkathimar/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a(NearCacheDataRecord.cpp.o): relocation R_X86_64_32S against symbol _ZTVN9hazelcast6client8internal9nearcache4impl6record23AbstractNearCacheRecordINS0_13serialization5pimpl4DataEEE' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/radkathimar/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a(ClientInvocationFuture.cpp.o): relocation R_X86_64_32S against symbol _ZTVN9hazelcast6client3spi4impl22ClientInvocationFuture35InternalDelegatingExecutionCallbackE' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/radkathimar/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a(ClientInvocation.cpp.o): relocation R_X86_64_32 against .rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/radkathimar/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a(LifecycleService.cpp.o): relocation R_X86_64_32S against .rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/radkathimar/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a(ClientProxy.cpp.o): relocation R_X86_64_32S against symbol _ZTVN9hazelcast6client3spi11ClientProxy21EventHandlerDelegatorE' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/radkathimar/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a(ProxyManager.cpp.o): relocation R_X86_64_32 against .rodata.str1.8' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/radkathimar/hazelcast-cpp-client/cpp/Linux_64/hazelcast/lib/libHazelcastClient3.12_64.a(ClientContext.cpp.o): relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIC

内容的提问来源于stack exchange,提问作者Raja Narayan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:03:23