0

Coming from programming environments that support package managers, I experience a lot of discomfort installing and using libraries not included in the default project.

For example, #include <threads.h> triggers an error threads.h file not found. I found that the compiler looks for header files in /Library/Developer/CommandLineTools/usr/include/c++/v1 by issuing gcc -print-prog-name=cpp -v. I am not sure if this a complete folder list? How do I find the ones that it doesn't find by default? I am on OSX, but Windows solution is also desired.

sanjihan
  • 5,592
  • 11
  • 54
  • 119

1 Answers1

0

The question doesn't really say whether you are building your own project, or someone else's, and whether you use an IDE or some build system. I'll try to give a generic answer suitable for most scenarios.

But first, it's header files, not libraries (which are a different kind of pain, by the way). You need to explicitly make them available to the compiler, unless they reside on a standard search path. Alas, it's a lot of manual work sometimes, especially when you need to build a third-party project with a ton of dependencies.

I am not sure if this a complete folder list?

Figuring out the standard include paths of your compiler can be tricky. Here's one question that has some hints: What are the GCC default include directories?

How do I find the ones that it doesn't find by default?

They may or may not be present on your machine. If they are, you'll have to find out where they are located. Otherwise you have to figure out what library they belong to, then download and unpack (and probably build) it. Either way, you will have to specify the path to that library's header files in your IDE (or Makefile, or whatever you use). Oh, and you need to make sure that the library version matches the version required by the project. Fun!

On macOS you can use third-party package managers (e.g. brew) to handle library installation for you.

pkg-config is not available on macOS, unless you install it from a third-party source.

If you are building your own project, a somewhat better solution is to use CMake and its find_package command. However, only libraries supported by CMake can be discovered this way. Fortunately, their collection of supported libraries is quite extensive, and you can make your own find_package scripts. Moreover, CMake is cross-platform, and it can handle versioning for you.

Roman Dmitrienko
  • 3,375
  • 3
  • 37
  • 48