Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In LINUX determine if a .a library/archive 32-bit or 64-bit?

We distribute in Linux a static lib in both 64-bit and 32-bit versions. When troubleshooting a customer, I would like my diagnostic shell script to quickly eliminate the issue by checking the .a archive file to detetmine whether it is 32 or 64 bit. The methods that occur to me are less than elegant:

  1. extract a .o member and ask the "file" command (e.g., ELF 32-bit etc)

  2. start including a dummy member coded to indicate, e.g. 32bit.o/64bit.o and use "ar -t" to check

I have tried "strings xyz.a | grep 32" but this doesn't work well over versions. Not a heartbreaker problem, but if you know of an elegant solution, I would like to know.

like image 317
cvsdave Avatar asked Apr 14 '11 15:04

cvsdave


People also ask

How do I know if my Linux file is 32-bit or 64-bit?

If you're interested in the CPU itself, look at /proc/cpuinfo for details about the CPU(s) detected by the Linux kernel. which tells us that it's a 32-bit executable using the Intel 80386 instruction set (possibly with extensions). Note that it isn't quite as simple as 32-bit versus 64-bit architectures.

How do you check if a shared library is 64-bit?

So, we can say /usr/lib/libc. a is a 64-bit static library. The “elf32-*” indicates all object files in the library use 32-bit addresses.

How do I get a 32-bit library?

To install 32-bit libraries on Ubuntu 13.04 (64-bit) or later, open Terminal and type: sudo apt-get install lib32z1 (you will need to enter your password). Then just for good measure, let's make sure your Ubuntu is up to date. Type sudo apt-get update and lastly, restart your computer.


1 Answers

objdump seems like the best way:

objdump -f libfoo.a | grep ^architecture 
like image 122
caf Avatar answered Nov 03 '22 07:11

caf