c - 如何让 ld 使用 PIC 版本的 libc.a
问题描述
要将gcc静态链接到共享库中,根据this question中的答案,剩下的问题是如何让链接器使用libc.a的PIC版本而不是非PIC版本。问题与该答案相同:
g++ -fPIC -Wall -O0 -fexceptions -g -c main.cpp -o main.o
ld -shared -static -o test.so main.o -lc
ld: //usr/lib/x86_64-linux-gnu/libc.a(malloc.o): relocation R_X86_64_TPOFF32 against `tcache' can not be used when making a shared object; recompile with -fPIC
这是我尝试过的:
sudo apt-get install libc-pic //then libc6-pic get installed successfully
ld -shared -static -o test.so main.o -lc //same as above, same error
ld -shared -static -o test.so main.o -lc-pic //not working: cannot find -lc-pic
ld -shared -static -o test.so main.o -lc6-pic //not working: cannot find -lc6-pic
解决方案
查看包中的文件列表有一个libc_pic.a
所以正确的选项似乎是-lc_pic
.
推荐阅读
- javascript - 控制多个范围滑块 Django 表单
- python - 打印是 3 的幂的数字。我可以更好地编写这个程序吗?
- python - 我如何使用 tkinter 按钮导入文件
- python - 将 Python 与 SQL Server 连接起来
- cmake - 添加消毒剂仅用于调试 CMake 中的构建
- google-cloud-platform - 谷歌云平台 Kubernetes 的云位置(GKE)
- events - 对发出的事件做出反应时,Unix Dialog 实用程序在 fish shell 中失败
- google-sheets - 更改工作表名称后,Google 表格查询返回异常结果
- java - Java InputStream 读取字符 \" 而不是显示为 " 用于 html 内容文件
- python - Python:从 cos(a) 和 sin(a) 值中找到角度 [0:360] 的度数