Linux 上的共享库和

编程入门 行业动态 更新时间:2024-10-25 16:21:55
本文介绍了Linux 上的共享库和 -fPIC 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am trying to compile a shared library in Linux using a Makefile created with Cmake, but running make I obtain the following error:

   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

I provide the following command in the CMakeLists.txt in order to say that I want a shared (.so) library:

add_library(cpp-lib SHARED ${CPP_FILES})

What else do I need to specify in order to avoid the -fPIC error shown above?

Thanks a lot in advance

解决方案

The boost libraries needs to be compiled using -fPIC: Please have a look at: How to compile static library with -fPIC from boost.python

Try to add compiler flags by cmake by in your project:

set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

这篇关于Linux 上的共享库和 -fPIC 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 04:38:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/796023.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Linux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!