cnandreu
cnandreu

Reputation: 5111

Build and guard against missing library using Objective-C

I have a library (lib.a) and a header file (lib1.h). The problem is the library is too big and only a relatively small subset of users need it.

ld: library not found for -llib

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Side note:

In Java I would use reflection to call methods implemented in the library (lib.jar) and if the library is not present I would catch the ClassNotFoundException and show an error message or something (lib.jar missing, please consult the documentation).

I'm targeting >= iOS5.

Upvotes: 2

Views: 153

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726849

Unlike desktop operating systems which support dynamic libraries, iOS supports only static libraries. The only way around this would be building two targets - one that uses the library, and the other one that does not.

You can build both targets from the same set of sources by using conditional compilation. In the version that conditionally compiles out the references to the "big library" there would be no references to it, so the linker would not complain about missing references.

Upvotes: 2

Related Questions