Is there any method to find out a static library is compiled with -fPIC flag
Asked Answered
P

1

6

I have a bunch of static libraries in my hand, which all have two versions -- 32bit and 64bit. When I use these static libraries to compile into a shared library, weird things happened: 1. I use 64bit static libraries to compile a 64bit shared library, everything works well; 2. I use 32bit static libraries to compile a 32bit shared library, ld tells me that the [text section is not shareable].

So, I guess that 32bit static libraries don't use -fPIC flag, but my colleague tells me he dit add the flag. But I still suspect that, so is there a way to find out whether the static library do add the -fPIC flag. PS: I know use readelf or objdump may get some clues, but is there a better way?

Pithecanthropus answered 14/9, 2015 at 9:6 Comment(1)
Z
-1

I believe, if you are using linux, you can check out the output of file

file myLib.so
file myLib.a

The output should inform you if the library was compiled with -fPIC

Zibeline answered 14/9, 2015 at 13:1 Comment(6)
well, I tried. I build test.o and test_pic.o by myself, but the output is all: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not strippedPithecanthropus
Do you run file for the objects, or the library?Zibeline
I run for the objects file. If run for the library, libtest.a for example, the output will only tell : 'archive file'.Pithecanthropus
Hmm... Try running for libtest.so. It should say more than that. libtest.a is indeed an archive of object files, so that's why file reports it as such.Zibeline
Well, what I need is identify a static library. So, this may don't work.Pithecanthropus
Oh, okay,, Sorry this didn't work, best of luck finding your answer :)Zibeline

© 2022 - 2024 — McMap. All rights reserved.