Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static libraries in version-cross-compiled program

I have a unix command line app (with big nasty makefile) that I'm trying to run on a mac. I am compiling it on a 10.6 system, with all of the appropriate libraries of course. The deployment environment is a 10.5 system, with no extra libraries.

I compiled without -dynamic, and it appears to have static libraries, correctly. When I run it on the 10.6 system, it works. However, when I run it on the 10.5 system, I get:

dyld: unknown required load command 0x80000022

I got this same error when I compiled things for the 10.6 system using the 10.5 xcode, so it looks like a version mis-match type problem. However, I used gcc-4.0, and

$CFLAGS = -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5

so it SHOULD be set up for 10.5... any ideas?

thanks

Editing an ancient question:

I have the exact same problem on a different computer. This time I am at 10.5.8, fully update, the same executable works on 10.6 still.

Has anyone had any luck with this in the months since I asked this?

like image 960
Brian Postow Avatar asked Sep 17 '09 18:09

Brian Postow


People also ask

Is .LIB a static library?

Examples of static libraries (libraries which are statically linked) are, . a files in Linux and . lib files in Windows.

What is static in GCC?

The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run. To achieve static linking requires that the archive ( . a ) versions of your libraries exist on the system. so /usr/lib/libc.

How are static libraries linked?

Static libraries are either merged with other static libraries and object files during building/linking to form a single executable or loaded at run-time into the address space of their corresponding executable at a static memory offset determined at compile-time/link-time.

What is static library libc A?

A static library is usually identified by a . a (for "archive") suffix (e.g. libc. a). The library contains the modules you want to include in your program and is formatted as a collection of ELF object modules that the linker can then extract (as required by your program) and bind with your program at link time.


2 Answers

The reason for the dyld 0×80000022 error can be that, you are linking on OS X 10.6, and OS X 10.6 will use a load command (LC_DYLD_INFO_ONLY = 0×80000022) that OS X 10.5 does not understand.

To fix this, make sure you are using a deployment target by setting the environment variable just before your link command:

export MACOSX_DEPLOYMENT_TARGET=10.5

(or setenv MACOSX_DEPLOYMENT_TARGET=10.5)

You can always check if your executable uses the right load command like this:

otool -l executable 

It will either show LC_DYLD_INFO_ONLY (without deployment target) commands or LC_DYLD_INFO (with deployment target).

like image 116
greymfm76 Avatar answered Sep 22 '22 05:09

greymfm76


I have been searching for the same issue, as I develop on 10.6 but must have a version that works on 10.5. In addition to the compiler flags above, you should add:

-no_compact_linkedit

It is described here:

http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/ld.1.html

where it says:

Normally when targeting Mac OS X 10.6, the linker will generate compact information in the __LINKEDIT segment. This option causes the linker to instead produce traditional relocation information.

I got there from a discussion on the xcode-users mailing list about "unknown required load command 0x80000022".

like image 31
todbot Avatar answered Sep 19 '22 05:09

todbot