I'd like to know whether an object or .a file is compiled with -fPIC enabled or not. Is there a way to know it (on both Linux and Mac OS X)? Thanks.
            Asked
            
        
        
            Active
            
        
            Viewed 871 times
        
    0
            
            
        - 
                    Have you tried using the `file` command? – Barmar Jan 24 '19 at 15:06
- 
                    It doesn't show the info. Is there an option to specify. $ gcc -fPIC -c print.c $ file print.o print.o: Mach-O 64-bit object x86_64 $ gcc -c print.c $ file print.o print.o: Mach-O 64-bit object x86_64 – user1424739 Jan 24 '19 at 15:10
- 
                    It was just a guess.... – Barmar Jan 24 '19 at 15:10
- 
                    That one is based on readelf and binutils is not supported well on Mac OS X. So this is not a duplicate. – user1424739 Jan 24 '19 at 15:15
- 
                    https://stackoverflow.com/questions/48622448/tell-if-a-shared-library-was-compiled-with-position-independent-code tells how to do it on OS X with `otools`. Google is your friend. – Barmar Jan 24 '19 at 15:20
- 
                    Again. Please test on your own. It doesn't work. I need .a or .o file. It shows executable. – user1424739 Jan 24 '19 at 15:23
- 
                    3Possible duplicate of [How can I tell, with something like objdump, if an object file has been built with -fPIC?](https://stackoverflow.com/q/1340402/608639) and [Tell if a shared library was compiled with position independent code](https://stackoverflow.com/q/48622448/608639). – jww Jan 24 '19 at 22:38
- 
                    Again, these are not for Mac. – user1424739 Jan 24 '19 at 22:45
