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建立了联系 ...
随机推荐
- Android Studio 引入 so 文件
1.在build.gradle中添加配置 task nativeLibsToJar(type: Zip, description: "create a jar archive of the ...
- 用gcc编译成可执行程序 (转)
#gcc hello.c 该命令将hello.c直接生成最终二进制可执行程序a.out 这条命令隐含执行了(1)预处理.(2)汇编.(3)编译并(4)链接形成最终的二进制可执行程序.这里未指定输出文件 ...
- 【linux】Crontab 定时任务 使用实例
1 使用putty 登录linux 服务器 2 输入以下命令.查看已有的定时任务 crontab -l 3 输入 以下命令,进入定时任务文件 crontab -e 4 键盘 选择 i 键 进行输 ...
- Linux学习——定义命令行函数(cd .. -> ..)
在使用shell的时候,每天要面对各种命令行,比如ls , cd .. 等 抱着简单,可依赖的思想.有些可以简化的操作可以要通过在 ~/.bashrc 中进行添加: 1. cd .. -> .. ...
- C++虚继承的概念[转]
C++中虚拟继承的概念 为了解决从不同途径继承来的同名的数据成员在内存中有不同的拷贝造成数据不一致问题,将共同基类设置为虚基类.这时从不同的路径继承过来的同名数据成员在内存中就只有一个拷贝,同一个函数 ...
- bootstrap之输入框组
向输入域添加前缀和后缀的内容 <div style="padding: 100px 100px 10px;"> <form class="bs-exam ...
- linux动态查看某组进程状态的办法
这里记录一下我监控某组进程的解决办法. 1.首先要获取要监控的进程的进程id,如果你要勇ps grep 那你就out了,强大的linux系统有一个pidof命令,用来查找相关进程的进程id,其实还有一 ...
- Unity3D之Unity3D 4.3.0 破解方法
Dear All 破解有风险,破解不尊重知识产权,如果有涉及请删除或者联系我……以下呢 是我这几天捣鼓的4.3.0版本 供学习!请大家支持正版! 1.下载最新版本 我是在Unity官网下载的最新版本 ...
- WCF学习 (三)深入认识WCF契约
什么是契约? 从SOA概念上讲,契约属于服务公开接口的一部分.一个服务契约,定义了服务端公开的服务方法,使用传输协议,可访问地址,传输的消息格式等内容.换句话说:契约描述了该服务的功能和作用,它告诉S ...
- thinkphp发起网络请求
常规做法使用CURL方法: private function http_request($url,$data = null,$headers=array()){ $curl = curl_init() ...