views:

170

answers:

2

I have a library compiled into a .a file, linked against my application. (iphone, developing with Xcode)

Everything seems to be fine, linking seems to succeed, but when I run the program it crashes. The point of crash is at a memcmp() call in the statically linked library. The debugger shows all kind of stuff called with "dyld" in their names, so it seems that for whatever reason it can not resolve memcmp, starts looking for dynamic libraries, then fails.

AFAIK memcmp is in libc, so should not be a problem. (tried also passing -lc to the linker, and it did not help, just as I expected)

So how it is supposed to work? Why can't a statically linked library use anything from libc? How should I compile it?

Thank you

A: 

libc is apparently dynamically linked on your platform. A matching version cannot be found at runtime to satisfy the dependency generated at link time.

I can't explain how this would happen other than filesystem corruption or calling chroot before the dynamic linking happens (which would seem unlikely).

Southern Hospitality
The strange thing is that I can call memcmp() from my main program, but the library still can't use it.
Some compilers handle memcmp() as an intrinsic. That is, if you call it, it puts code in place to implement it instead of calling out to a library function.
Southern Hospitality
A: 

Perhaps someone will find it useful if I share what the problem was:

The library was not compiled for the same OS version as the main program, so it was expecting a different libc than what it found when running.