g ++编译错误:制作共享对象时不能使用`.rodata';用-fPIC重新编译 [英] g++ compile error: `.rodata' can not be used when making a shared object; recompile with -fPIC

查看:701
本文介绍了g ++编译错误:制作共享对象时不能使用`.rodata';用-fPIC重新编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用命令:

g ++ --std = c ++ 11 -fPIC -Iincludes parser.cpp lib / main-parser.o lib / lib.a



在Debian 9上编译一个C ++程序。但是我得到了下面的错误信息:

/ usr / bin / ld:lib / lib.a(csdocument.o):在创建共享对象时,无法使用针对'.rodata'的重定位R_X86_64_32;使用-fPIC
/ usr / bin / ld重新编译:最终链接失败:输出上的非代表性部分
collect2:错误:ld返回1退出状态



我已经看过线程:

/ p>

然而,我尝试添加 -fPIC 参数,但它奇怪地给出相同的错误消息,以及重新编译与-fPIC



任何想法将不胜感激。我已经试过在我的大学的RedHat系统上编译这个,并且它在那里工作得很好。我想这可能是一个缺失的依赖项,但我一直无法找到任何答案。



提前致谢


<$ p $

p> g ++ --std = c ++ 11 -no-pie -Iincludes parser.cpp lib / main-parser.o lib / lib.a

默认情况下,系统中似乎 g ++ 会生成与位置无关的可执行文件。其他系统需要 -pie 才能这样做。使用 -no-pie 应该创建一个常规(取决于位置)的可执行文件。


I am using the command:
g++ --std=c++11 -fPIC -Iincludes parser.cpp lib/main-parser.o lib/lib.a

To compile a C++ program on Debian 9. But I am getting the below error message: /usr/bin/ld: lib/lib.a(csdocument.o): relocation R_X86_64_32 against '.rodata' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: error: ld returned 1 exit status

I have already seen the thread: Compilation fails with "relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object"

However, I have tried adding the -fPIC argument however it strangely gives the same error message, along with "recompile with -fPIC"

Any ideas would be appreciated. I have tried compiling this on my University's RedHat systems and it works fine there. I'm thinking it could be a missing dependency, but I've been unable to find any answers.

Thanks in advance

解决方案

As it seems gcc is trying to produce a position-independent executable, tell it not to:

g++ --std=c++11 -no-pie -Iincludes parser.cpp lib/main-parser.o lib/lib.a

It seems that g++ produces position-independent executables by default on your system. Other systems would require -pie to do so. Using -no-pie should create a "regular" (position dependent) executable.

这篇关于g ++编译错误:制作共享对象时不能使用`.rodata';用-fPIC重新编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆