i am trying to use a boost library

#include "boost/date_time/gregorian/gregorian.hpp"

and my source file is in the same folder as boost. however, during compilation i get errors that directories that gregorian.hpp links to (boost/date_time/compiler_config.hpp) could not be found.

i've checked that all the files that gregorian.hpp links to are in the correct paths.

any feedback is appreciated.

regards,

Dani AI

Generated

Quick clarification and a few extra checks for (and follow-ups for , and ).

The core issue is the C/C++ preprocessor search order. Finding the top Boost header next to a source file is possible, but that header usually pulls in other Boost headers using the system-style include form. Those nested includes are resolved from the compiler’s include paths, not necessarily from the directory of the .cpp. That mismatch is why the first file was found but its dependencies were reported missing.

Practical fixes and recommended workflow:

  • Keep third-party libraries out of the project source tree, as suggested. This avoids name collisions and upgrade/portability problems (the concern raised).
  • Add the parent directory that contains the top-level boost folder to the compiler/IDE include paths (use the build system’s include mechanism rather than copying headers into the project). Example for CMake (modern style):
target_include_directories(MyTarget PRIVATE /absolute/path/to/include_root)
# path should be the directory whose child is the 'boost' folder
  • For IDEs: add that same parent folder to the “additional include directories” / header search paths.

Quick troubleshooting checklist:

  • Confirm the include path points to the directory that contains the boost folder (not to one of its subfolders).
  • On case-sensitive filesystems, check filename case.
  • Remove any accidental partial copies of Boost that could shadow the intended headers.
  • Use the compiler’s verbose/preprocessor include-output option to see exactly where the compiler is searching for headers.
  • If linker errors appear later, install/link the matching Boost binary libraries for the components that require linking.

These steps explain why moving a boost folder next to a source file can fail and give practical ways to fix and avoid the problem in future projects.

Recommended Answers

All 5 Replies

> and my source file is in the same folder as boost.
This is a mistake - don't put your code in the same place as third-party libraries.

In essence, you should have
gcc -I/path/to/boost prog.c

Where /path/to/boost is the top-level directory of where your boost header files are installed (say /usr/include/boost)

If you're using some IDE, then how you configure compiler search paths depends on that IDE.

There is some kind off settings problem with your files. I can't think of any other reason. Check again.

thanks that was it ...

> and my source file is in the same folder as boost.
This is a mistake - don't put your code in the same place as third-party libraries.

Is this bad practice or simply illegal? How/why should it affect anything?

I don't mean to challenge you or anything. I'm learning and my text doesn't seem to address the issue.

> Is this bad practice or simply illegal? How/why should it affect anything?
It's just bad practice.
If the library gets updated, and it just happens to use the same filename as one you've chosen, it's bye bye code for you.

Also, anyone else trying to use the same library code (or even you on another project) risk picking up unintended files.

Plus when source is distributed, it always exists in separate directory structures.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.