22

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?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Setjmp
  • 27,279
  • 27
  • 74
  • 92
  • possible duplicate, but no answer there seems to be correct: http://stackoverflow.com/questions/1340402/how-can-i-tell-with-something-like-objdump-if-an-object-file-has-been-built-wit – ergosys Aug 17 '10 at 22:40
  • Possible duplicate of [How can I tell, with something like objdump, if an object file has been built with -fPIC?](https://stackoverflow.com/questions/1340402/how-can-i-tell-with-something-like-objdump-if-an-object-file-has-been-built-wi) – Ciro Santilli OurBigBook.com Oct 26 '17 at 05:24

2 Answers2

21

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
Community
  • 1
  • 1
-3

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
F'x
  • 12,105
  • 7
  • 71
  • 123