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

前端 未结 5 1844
既然无缘
既然无缘 2021-01-30 07:53

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

相关标签:
5条回答
  • 2021-01-30 08:26

    The simplest way is to use the file command.

    $file <.so file or .a file>
    
    0 讨论(0)
  • 2021-01-30 08:33

    objdump seems like the best way:

    objdump -f libfoo.a | grep ^architecture
    
    0 讨论(0)
  • 2021-01-30 08:33

    Just use the file command; i.e. file library.so

    0 讨论(0)
  • 2021-01-30 08:41

    oops, that missing sed means that it was displaying to many items.

    Just in an answer:

    count=$(nm foo.a | grep '^0' | head -1 | sed 's/ .*//' | wc -c)
    ((count == 17)) && echo 64bit
    ((count == 9)) && echo 32bit
    ((count == 0)) && echo '??bit'
    

    How it's supposed to work:

    • nm - get the symbols from the library
    • grep - get lines starting with a hex string (address of symbol in file)
    • head - get the first line
    • sed - remove everything past the whitespace, including the whitespace
    • wc - count the number of characters.

    In a 32 bit environment, you get addresses made up of 8 hex digits, adding the new line gives you 9, In a 64bit environment, you get addresses made up of 16 hex digits, adding the new line gives you 17.

    0 讨论(0)
  • 2021-01-30 08:49

    If there are functions that are specific to a particular version you could try nm then grep for the function.

    0 讨论(0)
提交回复
热议问题