How to Check If a Static Library Is Built for 64-Bit

How to check if a static library is built for 64-bit?

Yes, an arm64 slice is there. To see it, you need to use lipo from the iOS toolchain, not from the host system (which doesn’t know about arm64):

xcrun -sdk iphoneos lipo -info $(FILENAME)

Have a static lib, is there a simple way to know it is for 32 bit or 64 bit?

You can use dumpbin utility with /headers option

It returns whether the library was built for 32 or 64 bit architecture.

Check DUMPBIN Reference for details.

Example usage:

c:\>dumpbin libXYZ.lib /headers

Determining the CPU architecture of a static library (LIB) on Windows

Use dumpbin /headers

The machine type is almost the first line you'll get.

It will be 14c for x86 and 8664 for x64

n:>dumpbin lib642.lib /headers

Microsoft (R) COFF/PE Dumper Version

10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved.

Dump of file lib642.lib

File Type: LIBRARY

FILE HEADER VALUES
8664 machine (x64

Or

n:>dumpbin Lib32.lib /headers

Microsoft (R) COFF/PE Dumper Version

10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved.

Dump of file Lib32.lib

File Type: LIBRARY

FILE HEADER VALUES
14C machine (x86)

check what run-time static library or dll uses

If it is a .lib file, a static link library, then you don't know anything about the CRT yet. It wasn't linked yet. You can find out about the original programmer's intention, use a hex viewer to look the .lib file, Notepad will do fine as well. You'll see the original command line that was used to compile the .obj files that were embedded in the .lib file. Simply search for "cl.exe", you'll have a good idea what compiler version was used from the path to cl.exe. And you can see the command line options so you'll know if /MD or /MT was in effect. And the /O option, important to have an idea whether you've got a Debug or Release build.

If it is a .dll file then dumpbin.exe /imports is your best choice. The dependency on the msvcrxxx.dll file will be visible, with xxx the version number like "120". If you see it then the name tells you if /MD or /MDd was used, "d" is appended for the Debug version of the CRT If it is missing then you know that /MT or /MTd was used, no hint about the build flavor available.

Following the recommendations from the library owner is always best, you can get into a lot of trouble when the CRT version or build settings of the library doesn't match yours. With non-zero odds that you have to ask him for an update, YMMV.

Can C code be compiled into a static library for any architecture?

All of this is possible, however it is somewhat hard without seeing your code.

Here is a little starter:

clang -c library.c -o library.x86_64.o -arch x86_64 // Compile your code to x86_64
clang -c library.c -o library.arm64.o -arch arm64 // Compile your code to arm64
libtool -static -o library.x86_64.a library.x86_64.o // Create a static intel lib
libtool -static -o library.arm64.a library.arm64.o // Create a static arm64 lib
libtool -static -o library.a library.x86_64.a library.arm64.a // Create a universal static lib

Without knowing your makefile or your Xcode project, there is not much I can say without doing a very big tutorial



Related Topics



Leave a reply



Submit