如何判断一个静态库(.a文件)所支持的架构(平台)

问:

How do I determine the target architecture of static library (.a) on Mac OS X?

I'm interested in verifying if a given iPhone static library has been built for ARM or Intel.

Its more curiosity than anything. Is there some kind of Mac OS X or BSD specific tool to do this? Thispost gives an example in Linux.


方法1:

file will probably tell you. otool certainly should be able to. But I'd try file first, e.g.

logan:/Users/logan% file d2
d2: Mach-O executable ppc

Example with archive:

logan:/Users/logan% file /usr/lib/libMallocDebug.a
/usr/lib/libMallocDebug.a: Mach-O universal binary with 2 architectures
/usr/lib/libMallocDebug.a (for architecture i386):      current ar archive random library
/usr/lib/libMallocDebug.a (for architecture ppc):       current ar archive

方法2:

Another option is lipo, it's output is brief and more readable that otool's.

Example:

% lipo -info /usr/lib/libiodbc.a 
Architectures in the fat file: /usr/lib/libiodbc.a are: x86_64 i386 ppc
% lipo -info libnonfatarchive.a
input file libnonfatarchive.a is not a fat file
Non-fat file: libnonfatarchive.a is architecture: i386
%


方法3:

As mentioned earlier, file does not always work. otool -hv is probably the closest thing that is guaranteed to work - it gives architecture information for every single object file in the library.

Example:

% otool -hv /sw/lib/libfftw3.a
Archive : /sw/lib/libfftw3.a
/sw/lib/libfftw3.a(align.o):
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
MH_MAGIC_64  X86_64        ALL  0x00      OBJECT     3        336 SUBSECTIONS_VIA_SYMBOLS
/sw/lib/libfftw3.a(alloc.o):
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
MH_MAGIC_64  X86_64        ALL  0x00      OBJECT     3        416 SUBSECTIONS_VIA_SYMBOLS


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Hadoop2.2.0 native lib 直接替换掉 2.2.0 发布包里面的nativeIO ,配置好环境变量就可以了 东西虽然小,但是却费了不少功夫,主要是由于本地网络控制,不允许上网。安装各种软件就费了很大劲,软件之间的依赖也很让人头痛, 希望能帮到有需要的兄弟姐妹。。。! 包含的文件: ~/hadoop/hadoop-2.2.0/lib/native> ll 总计 1540 -rw-r--r-- 1 weblogic users 734402 04-15 10:22 libhadoop.a -rwxr-xr-x 1 weblogic users 412856 04-15 10:22 libhadoop.so -rwxr-xr-x 1 weblogic users 412856 04-15 10:22 libhadoop.so.1.0.0 ~/hadoop/hadoop-2.2.0/lib/native> file * libhadoop.a: current ar archive libhadoop.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped libhadoop.so.1.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped 下面是查询的详细OS版本信息 #uname -a Linux F23-B4-E2-B3 2.6.32.12-0.7-default #1 SMP 2010-05-20 11:14:20 +0200 x86_64 x86_64 x86_64 GNU/Linux # lsb_release -a LSB Version: core-2.0-noarch:core-3.2-noarch:core-4.0-noarch:core-2.0-x86_64:core-3.2-x86_64:core-4.0-x86_64:desktop-4.0-amd64:desktop-4.0-noarch:graphics-2.0-amd64:graphics-2.0-noarch:graphics-3.2-amd64:graphics-3.2-noarch:graphics-4.0-amd64:graphics-4.0-noarch Distributor ID: SUSE LINUX Description: SUSE Linux Enterprise Server 11 (x86_64) Release: 11 Codename: n/a weblogic@F23-B4-E2-B1:~> cat /etc/SuSE-release SUSE Linux Enterprise Server 11 (x86_64) VERSION = 11 PATCHLEVEL = 1
在CMake中,你可以使用`add_library`命令创建一个目标,并将已有的静态库文件添加到该目标中。具体步骤如下: 1. 使用`add_library`命令创建一个空的目标,例如: ```cmake add_library(my_target STATIC) ``` 这将创建一个名为`my_target`的静态库目标。 2. 使用`target_link_libraries`命令将已有的静态库文件链接到目标中,例如: ```cmake target_link_libraries(my_target /path/to/my_library.a) ``` 其中,`/path/to/my_library.a`是你要链接的静态库文件的路径。 3. 将目标的源文件添加到目标中,例如: ```cmake target_sources(my_target PRIVATE source1.cpp source2.cpp ...) ``` 其中,`source1.cpp`、`source2.cpp`等是目标的源文件。 4. (可选)设置目标的包含目录和编译选项,例如: ```cmake target_include_directories(my_target PUBLIC /path/to/include) target_compile_options(my_target PRIVATE -Wall -Werror) ``` 这将使得目标能够正确地编译和链接,并且能够使用库文件中的函数和变量。 完整的示例代码如下: ```cmake add_library(my_target STATIC) target_sources(my_target PRIVATE source1.cpp source2.cpp ...) target_link_libraries(my_target /path/to/my_library.a) target_include_directories(my_target PUBLIC /path/to/include) target_compile_options(my_target PRIVATE -Wall -Werror) ``` 其中,`my_target`是目标的名称,`source1.cpp`、`source2.cpp`等是目标的源文件,`/path/to/my_library.a`是要链接的静态库文件的路径,`/path/to/include`是要包含的头文件的路径,`-Wall -Werror`是要使用的编译选项。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值