c++ - Getting error "can not be used when making a shared object; recompile with -fPIC" although fpic is used
问题描述
I am currently building a shared library (lib1.so) out of a cmake environment. lib1.so depends on an external static lib libLASlib.a (which I am able to recompile if necessary). Everything works wonder on windows so far, but it's another story when switching to linux:
/usr/bin/ld: lib/LASlib/libLASlib.a(lasreader.cpp.o): relocation R_X86_64_PC32 against symbol `_ZN9LASreader35read_point_filtered_and_transformedEv' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
So I tried recompiling the libLASlib with -fPIC -> same error
Due to my environment I could not verify the fpic was effectivelly added to the gcc command line.
Here is what I tried to confirm there was no issue with the fPIC:
readelf --dynamic libLASlib.a | grep lasreader.cpp.o -A2
File: libLASlib.a(lasreader.cpp.o)
There is no dynamic section in this file.
For the record not a single cpp.o was found with a dynamic section
I have tried just to see what it would give if i changed liblas from a static to a shared library -> no error
Any thoughs? Many thanks!
解决方案
确实没有应用 fPIC
柯南似乎没有转发 fPIC 选项
我编辑了 CMAKELIST 并添加了
set_property(TARGET LASlib PROPERTY POSITION_INDEPENDENT_CODE ON)
它最终通过了
推荐阅读
- azure - 为什么从 Azure Functions 2.x 中删除通知中心输出绑定?
- lucene - Azure 搜索如何选择查询提升值
- spring-boot - RequestMethod.GET 没有被激发
- arrays - VB.net 如何从列表中删除已经在数组中的项目
- matlab - 如何用matlab求解不同参数值的ODE?
- react-native - 更新应用程序时如何注销用户
- java - Java 软件:在特定日期后禁用
- mysql - 复杂查询 orddr by 和 group by 一起在语句上
- c# - WPF 在添加新行之前禁用与 DataGrid 的 TemplateColumn 交互
- javascript - 正则表达式 - 查找可以包含字符但不能以字符结尾的模式(javascript)?