fpic - 使用 -fPIC 重新编译
问题描述
我写了这个命令:
gcc drr.c -o drr -pthread -lcdsl -L./../synch_implementations -I./../synch_implementations
我不明白为什么我会得到这个回复:
usr/bin/ld: ./../synch_implementations/libcdsl.a(cdsl_queue_list.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
usr/bin/ld: ./../synch_implementations/libcdsl.a(cdsl_deque_list.o): relocation R_X86_64_32S against symbol `cdsl_deque_list_lock_based_pthread_push_tail' can not be used when making a PIE object; recompile with -fPIC
usr/bin/ld: ./../synch_implementations/libcdsl.a(cdsl_lock.o): relocation R_X86_64_32S against symbol `cdsl_pthread_lock_request' can not be used when making a PIE object; recompile with -fPIC
usr/bin/ld: final link failed: Nonrepresentable section on output
ollect2: error: ld returned 1 exit status
谁能帮我理解什么是错的?
笔记:
1)我使用ubuntu(通过VirtualBox)。
2)我非常缺乏经验,所以这可能不是一个很聪明的问题。
解决方案
解决方案:当您编译 ./../synch_implementations/libcdsl.a 时,您需要添加一个额外的“-fPIC”标志来生成与位置无关的代码(参见上面的注释)。
注意:生成库对象代码时通常需要 PIC 标志,因为它创建相对于全局偏移表 (GOT) 的对象,随后允许将库对象与您的代码链接。
推荐阅读
- ionic-framework - 使用 Ionic 3 中的相机拍摄的 FTP 上传图像
- typescript - 在 vscode 中快速调试打字稿
- python - Plotting a Function Over Multiple Constants
- javascript - NodeJS:为什么 new Date().toLocaleString() 忽略系统时区?
- java - Error in netbeans when try to run program: Truncated module-info.class
- scala - 如何将 Spark 数据集字段(包装数组)转换为 Spark Java 中的映射或数组列表
- build - Artifactory 可以根据构建时间而不是版本号来保留构建吗?
- javascript - Django 表单不显示日期小部件
- c# - WPF 中的绑定验证
- php - 快速以纵向模式拍摄照片并上传到服务器 - 上传的图像显示方向错误