0

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

cdespinosa
  • 20,661
  • 6
  • 33
  • 39
  • 1
    Is the library you have linked against your application one you have written yourself? - I can't help suspecting that it's using an uninitialized or null pointer. Or maybe you're not using the library properly which causes the invalid pointer? What does the backtrace say? – James Morris Nov 14 '09 at 00:17
  • No, it's a widely used library, working reliably on a lot of platforms, and it fails at the very start, with an initializer function. The same code snippet (actually 2 function calls to set things up) The backtrace points to a memcmp function. (the library was compiled in debug mode) –  Nov 17 '09 at 15:48

2 Answers2

0

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
  • 1,260
  • 1
  • 8
  • 12
  • The strange thing is that I can call memcmp() from my main program, but the library still can't use it. –  Nov 17 '09 at 15:49
  • 1
    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 Nov 19 '09 at 07:46
0

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.