You can do it using weak functions.
In your static library, declare all function of ccc that you want to use like this:
int cccfunction(void) __attribute__((weak));
Don't include ccc in you lib.
Since the functions are declared as weak, the compiler wouldn't complain about their absence, however you will be able to reference it in you code.
Then, when you distribute the library to your users, give them a .c file with empty ccc functions inside, returning 0/null.
This is necessary when the ccc lib is not available.
The user must delete this file if the CCC library is imported.
LOOK at this project
execute IOSLibraries and look at the log.
At the first execution, you will see in the log
CCC not found <--- this line is printed by libstatic (your library)
if you go in the optional.c file and comment the cccfunction(), you will see in the log
Executing a function of CCC <--- this line is printed by libccc
CCC has been found and the function has been executed <--- this line is printed by libstatic (your library)
If you remove both the ccc lib and the optional.c file you will see
Undefined symbols for architecture xxxxxx:
"_cccfunction", referenced from:
_wrapper_cccfunction in libstaticfirst_universal.a(wrapper_cccfunction.o)
This is the reason why you need to ship the optional.c file, so the user compiler won't complain about not found methods.
When the user has the CCC lib, he can simply delete or comment the optional.c file.
In your library you will be able to test for the presence of the CCC library looking at the return value of some control functions
EDIT - old answer: after realizing that you are on iOS, the below (and first) answer became not valid. Dynamic linking works only on OSX. However, I leave the old answer for persons using OSX
OLD ANSWER
I think that
I assume that CCC is a static library (if it's dynamic it's simpler). In this case, AFAIK, you can do nothing "automagically", but a good compromise can be something like this, using Dynamic libraries
user project --include--> your static library --include--> a dynamic library --can include–-> the CCC library
create two version of the dynamic library:
one that implements, for example, empty functions of the CCC library -> when you call the function, they returns 0/null and you know that the library is not implemented. You can even use something smarter (a simple control function)
give to the users the source code of a second dynamic library, that they can compile simply by doing drag-drop of the CCC library inside the project, and then moving the compiled library in the right place. This is not the source code of your library (your code is compiled in the static part), but only the code of the wrapper functions that you call from your static libraries.
your static library don't call directly functions of the CCC library, but only wrapper functions that always exists (in both the "empty dynamic library" and in the "compiled-by-user dynamic library")
By doing this, the user can replace the "empty" dynamic library with the one that include CCC.
If the dynamic library is the one with the CCC linked, the final project will use the function of CCC, otherwise it won't.
Look at the attached example:
- LibTests project implements the lib libstaticlib.a and call its function "usedynamic(int)"
- libstaticlib.a implements the dynamic library libdynamic1 and call its function "firstfunction(int)"
- libdynamic1 has two different copies: one has a firstfunction() that returns the number passed, the other returns the number*2
now, open LibTests (that should be project of your user), copy the first of the two compiled dynamic libraries in /usr/local/lib/ , then execute LibTests: you will see "10" in the console.
Now, change the dynamic library with the second, and you will see "20".
This is what the user have to do: you sell the library with a dynamic "empty" component. If the user has bought CCC, you give instruction and code on how to compile the dynamic component with CCC bundled with it. After the dynamic library has been built, the user has simply to switch the .dylib file