Linux上的共享库和-fPIC错误

 李慧颖yynd_613 发布于 2022-12-15 15:17

我正在尝试使用使用Cmake创建的Makefile在Linux中编译共享库,但是运行make我获得以下错误:

   Linking CXX shared library libcpp-lib.so
   /usr/bin/ld: /home/davide/Desktop/boost_1_55_0/stage/lib/libboost_system.a(error_code.o): relocation R_X86_64_32 against .rodata.str1.1 can  not be used when making a shared object; recompile with -fPIC
   /home/davide/Desktop/boost_1_55_0/stage/lib/libboost_system.a: could not read symbols:   Bad value
   collect2: ld returned 1 exit status
   make[2]: *** [libcpp-lib.so] Error 1
   make[1]: *** [CMakeFiles/cpp-lib.dir/all] Error 2
   make: *** [all] Error 2

我在CMakeLists.txt中提供以下命令,以便说我想要一个共享(.so)库:

add_library(cpp-lib SHARED ${CPP_FILES})

为了避免上面显示的-fPIC错误,还需要指定什么?

非常感谢提前

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有