2

Suppose I want to include a library:

#include <library.h> 

but 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.

4
  • What operating system are you using? Autotools would imply Linux, correct? Commented Feb 2, 2011 at 20:11
  • 2
    Exceptions are a run-time thing; #include is a (pre-)compile-time thing. If the header file doesn't exist, the compiler will bomb out. What do you intend on doing if that were to happen? Commented Feb 2, 2011 at 20:15
  • #include <library.h> is not including a library. Perhaps this is merely semantics, but a ridiculously large percentage of the population does not understand that, so it would be wise to rephrase the question. Commented Feb 4, 2011 at 11:13
  • @trojanfoe Autotools does not imply Linux. The point of the autotools is to provide a portable package that will work on a large variety of unix-ish systems, including Linux. Commented Feb 9, 2011 at 15:01

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

Those who do not understand the autotools are doomed to reinvent them. Autoconf is a tool that builds a script exactly like you are describing. It is much easier to learn autoconf than it is to re-discover all of the pain involved in writing such a script.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.