check if a library is present
Suppose I want to include a library:
#include <library.h>
b开发者_C百科ut I'm not sure it's installed in the system. The usual way is to use tool like autotools. Is there a simpler way in C++? For example in python you can handle it with exceptions.
autotools is the best way to detect at compile time. It's very platform-specific, but assuming you're on Linux or similar, dlopen is how you check at runtime.
As far as I know, there's no way of checking whether a library is installed using code. However, you could create a bash script that could look for the library in the usual places, like /usr/lib or /usr/local/lib. Also, you could check /etc/ld.so.conf for the folders and then look for the libraries.
Or something like that.
精彩评论