gcc报错 can not be used when making a shared object; recompile with -fPIC
使用google protobuf时,出现错误
/usr/bin/ld: /usr/local/lib/libprotobuf.a(message_lite.o): relocation R_X86_64_32S against `_ZTVN6google8protobuf11MessageLiteE' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libprotobuf.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
搜了下,几篇文章如下:
查看整个编译过程,编译过程中看到没有-fPIC选项,如何加进去
看protobuffer的README和INSTALL文档,看到需要添加特殊编译选项,需要在执行configure的时候引入,
于是make clean; make uninstall
./configure CXXFLAGS=-fPIC
查看编译文件,发现已经有了编译选项-fPIC,再次执行编译安装
重新编译程序,这次没有报错,没有出错,问题解决。
另外回答;
原因:
-fPIC 是个神马东东呢?
选项 -fPIC
PIC是Position-Independent-Code的缩写。在计算机系统中,PIC和PIE(Position-IndependentExecutable)是可以在主存中不同位置执行的目标代码。PIC经常被用在共享库中,这样就能将相同的库代码为每个程序映射到一个位置,不用担心覆盖掉其他程序或共享库。
因为so动态库编译的时候加上了 -fPIC,但是连接的 libprotobuf.a文件并不是 -fPIC生成的,所以就报错了。
那就是说连接的 libprotobuf.aa 文件,也需要加上 -fPIC 选项进行编译了。
关于-fPIC:http://blog.sina.com.cn/s/blog_54f82cc201011op1.html
/usr/bin/ld: libs/X86_64/libglog.a(libglog_la-logging.o): relocation R_X86_64_32S against `_ZTVN6google4base6LoggerE' can not be used when making a shared object; recompile with -fPIC libs/X86_64/libglog.a: could not read symbols: Bad value collect2: error: ld returned 1 exit status
只能安装错误提供的方法重现编译libglog.a了,然后,替换了libglog.
CXXFLAGS="-O3 -fPIC" ./configure --prefix=glog-0.3.3/install
参考:http://zrj.me/archives/1066
gcc报错 can not be used when making a shared object; recompile with -fPIC的更多相关文章
- 【Linux】 解决报错: ImportError: libSM.so.6: cannot open shared object file: No such file or directory
centos7 + python3.6.4 我使用 pip3 install opencv-python 安装了opencv-python 之后,在使用 import cv2 报错如下 报错原因 ...
- [one day one question] webpack 打包报错 Cannot assign to read only property 'exports' of object '#<Object>'
问题描述: webpack 打包报错 Cannot assign to read only property 'exports' of object '#<Object>',这怎么破? 解 ...
- suse linux编译安装GCC报错
gcc编译安装过程 1.先安装三个库 gmp mprc mpc 这三个库的源码要到官网去下载 1)安装gmp:首先建立源码同级目录 gmp-build,输入命令,第一次编译不通过,发现缺少一个叫m4的 ...
- linux下安装redis组件报错-gcc报错
报错如图: 1.解决办法 先安装gcc插件.删除redis解压后文件.重新解压
- 编译gcc报错make[3]: Leaving directory `/usr/local/src/gcc-7.4.0/build/gcc' make[2]: *** [all-stage1-gcc] Error 2 处理
因业务需要安装7.4高版本gcc时报错: configure: error: in `/usr/local/src/gcc-7.4.0/build/gcc': configure: error: C+ ...
- Win下GCC报错 error: ‘for’ loop initial declarations are only allowed in C99 mode
##报错## 用GCC编译for循环会出现以下错误 error: 'for' loop initial declarations are only allowed in C99 mode 如图所示: ...
- PyCharm+selenium环境搭建报错:Traceback (most recent call last): TypeError: 'module' object is not callable
环境搭建好后,代码如下: from selenium import webdriverdriver = webdriver.chrome()driver.get("http://www.ba ...
- E: Invalid operation build-depgcc(给字符界面的ubuntu安装gcc 报错
sudo apt-get build-depgccE: Invalid operation build-depgcc 原因是中间少了个空格, 使用如下命令即可. sudo apt-get buil ...
- React报错Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function`
引言 最近在忙毕业设计,博客也很久没更新了,毕业设计使用vue做了一个校园寻物网站,现在开始学Raect,记录一下自己遇到问题,react-redux的connect方法使得组件与Redux建立了联系 ...
随机推荐
- brew 的 调度工具DBGPRINTF 和 c语言的 printf
在官方的文档中是这样备注DBGPRINTF Prototype void dbgprintf(const char *pszFormat,...); Description This function ...
- Java精选笔记_面向对象(包、访问控制、内存机制、垃圾回收机制)
包 包的定义与使用 专门用来存放类的,通常功能相同的类存放在相同的包中. 包的声明只能位于Java源文件的第一行 Java语言中的常用包 java.lang:包含Java语言的核心类,如String. ...
- Host ‘host_name’ is blocked
参考:http://web2.0coder.com/archives/163 之前服务器遇到了这个错误: Host ‘host_name‘ is blocked because of many con ...
- Android 使用GridView以表格的形式显示多张图片
GridView用于在界面上按行.列分布的方式来显示多个组件(而ListView只是以按行的方式) 课程目标 学会使用GridView制作二维布局界面(行.列分布) 数据源(集合) --> 适配 ...
- thinkphp5 Windows下用Composer引入官方GitHub扩展包
很多新手,比如说我,写代码就是在windows下,所以总会遇到很多不方便的地方,比如说GitHub上面的代码更新了,要是你在linux,只要几行命令就可以搞定更新了,在windows下面,你需要用到C ...
- Delphi Code Editor 之 几个特性(转)
Delphi Code Editor有几个特性在编写大规模代码时非常有用.下面分别进行介绍: 原地址:http://www.cnblogs.com/pchmonster/category/343330 ...
- c# Use NAudio Library to Convert MP3 audio into WAV audio(将Mp3格式转换成Wav格式)
Have you been in need of converting mp3 audios to wav audios? If so, the skill in this article prov ...
- java如何随机生成定长的字符串
小数,字符串.时间等示例代码 String base = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 public c ...
- OC开发_Storyboard——block和动画
一.协议 @optional :可选的 @requied :必须实现的 二.block 代码块 1. 以一个^开头,然后是参数,然后是一个大括号,包含我们的代码块 [aDictionary enu ...
- jquery收集表单数组及去掉字符串最后的逗号!
jquery收集表单数组: <input type='text' name='one[]' value='' /><br> <input type='text' name ...