My program can make use of a certain library (let’s call it foo), and this library is non-free. So I don’t want to make it a dependency neither at compile time nor at run time. The library only provides nice-to-have extra features, so the program can do without foo. So I’m planning to do this:
- Let configure look for foo at compile time, and if not present, build the program without the extra features. This part is easy enough.
- If foo is present then #include foo.h, but don’t link to the shared library (because the program must be able to run without foo present), and instead use dlopen(foo.so) and dlsym().
So why do I want to include foo.h if I am going to use dynamic linking anyway? Well, because foo.h has all the definitions of the data types and enumerations I am going to need when using the functions in the library. There are a lot of these, and some of them are complex, so it seems like an easy way to get hold of them. And it seems to be working in my first tests.
However, I can’t find any examples of dlopen() usage where the library header is also being included, so I’m afraid I’m doing something completely stupid. I’ve never worked with dynamic linking before. So is this the proper way to do this?