有没有办法确定 .a 或 .so 库已编译为位置无关代码?

发布于 2024-09-14 22:53:15 字数 95 浏览 4 评论 0原文

针对 lapack 编译 numpy 库时出现链接错误,表明我需要使用 -fPIC 编译 lapack。我以为我已经做到了。有没有办法确定生成的 lapack 库是位置无关的?

I am getting a linking error when compiling the numpy library against lapack indicating I need to compile lapack with -fPIC. I thought I had done just that. Is there a way to determine that the produced lapack library is position independent?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伤痕我心 2024-09-21 22:53:15

您可能会运气好 这个答案,虽然它依赖于平台并且不适用于所有对象文件(但如果您的代码以任何方式操作指针,它应该可以工作)。

这是使用 -fPIC 编译的文件上 objdump -r 的结果:

test.o:     file format elf32-i386

RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE 
00000007 R_386_PC32        __i686.get_pc_thunk.cx
0000000d R_386_GOTPC       _GLOBAL_OFFSET_TABLE_

这是针对没有 PIC 的文件:

test.o:     file format elf32-i386

You may have some luck with this answer, although it's platform dependent and doesn't work for all object files (but if you code manipulates pointers in any way, it should work).

This is the result of objdump -r on a file compiled with -fPIC:

test.o:     file format elf32-i386

RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE 
00000007 R_386_PC32        __i686.get_pc_thunk.cx
0000000d R_386_GOTPC       _GLOBAL_OFFSET_TABLE_

and this is for a file without PIC:

test.o:     file format elf32-i386
半夏半凉 2024-09-21 22:53:15

一般来说,你无法知道:

$ cat a.c
int foo(int x) { return x+1; }
$ gcc -fno-pic a.c -c -o nopic.o
$ gcc -fPIC a.c -c -o pic.o   
$ cmp pic.o nopic.o 
$ cmp pic.o nopic.o && echo Identical
Identical

In general, you have no way of knowing:

$ cat a.c
int foo(int x) { return x+1; }
$ gcc -fno-pic a.c -c -o nopic.o
$ gcc -fPIC a.c -c -o pic.o   
$ cmp pic.o nopic.o 
$ cmp pic.o nopic.o && echo Identical
Identical
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文