问题描述
我们在 Linux 中分发了 64 位和 32 位版本的静态库.在对客户进行故障排除时,我希望我的诊断 shell 脚本通过检查 .a 存档文件来确定它是 32 位还是 64 位,从而快速消除问题.我想到的方法不够优雅:
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:
提取 .o 成员并询问文件"命令(例如,ELF 32 位等)
extract a .o member and ask the "file" command (e.g., ELF 32-bit etc)
开始包括一个虚拟成员编码以指示,例如32bit.o/64bit.o 并使用ar -t"检查
start including a dummy member coded to indicate, e.g. 32bit.o/64bit.o and use "ar -t" to check
我尝试过strings xyz.a | grep 32",但这在不同版本中效果不佳.不是一个令人心碎的问题,但如果你知道一个优雅的解决方案,我想知道.
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.
推荐答案
objdump
似乎是最好的方法:
objdump -f libfoo.a | grep ^architecture
这篇关于在 LINUX 中确定 .a 库/存档是 32 位还是 64 位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!