12

I'm trying to incorporate the Boost libraries into my program, specifically lexical_cast and geometry. I include them using #include"boost/boost/geometry.hpp" and #include"boost/boost/lexical_cast/lexical_cast_old.hpp".

When I run the code I get the fatal error "Cannot open include file: 'boost/geometry/geometry.hpp': No such file or directory" which leads me to another .hpp file in the Boost library which includes another library, but uses #include<...> instead of #include"...".

When I replace it for "..." the error for this one goes, but it is replaced with the next library included using #include<...> instead of #include"...".

I feel like this could lead me down a rabbit hole of replacing nearly all instances of #include<...> with #include"..." which would take ages. Is there a setting I can change or a piece of code I could include that would sort this out?

Or could I just get rid of all the other unnecessary libraries and change the ones I need (I know that, that would still be a lot as they seem to rely on each other).

I have Boost library version 1.58.0.

genpfault
  • 47,669
  • 9
  • 68
  • 119
Peter
  • 163
  • 1
  • 1
  • 6
  • You need to pass the compiler the include directories. Which compiler do you use? – Nidhoegger Apr 27 '15 at 10:36
  • instead of `boost/boost/`*filename* you should have `boost/`*filename*. Adjust your compiler's include path accordingly. Also use angle brackets for the include. – Cheers and hth. - Alf Apr 27 '15 at 10:40
  • I'm not sure, how do I find out? I'm using visual studios 2012 and writing in C++ – Peter Apr 27 '15 at 10:40
  • @Cheersandhth.-Alf when I use angled brackets to include the lexical_cast for example an error appearers on the `#include` saying cannot open the source file "...". How do I adjust my compiler's include path? – Peter Apr 27 '15 at 10:52
  • @Peter: it depends on the compiler. many compilers accept an `-I` (uppercase) followed by directory path, as command line option. with g++ you can specify paths in `CPATH` environment variable, which then is treated as a last `-I` option. correspondingly with Visual C++ you can use the `INCLUDE` environment variable. – Cheers and hth. - Alf Apr 27 '15 at 11:03

3 Answers3

12

First you should read about the difference between #include "filepath" and #include <filepath> here.

Personally, I'm working with Boost from Visual Studio as follows:

  1. Go to Project propertiesC/C++GeneralAdditional Include Directories, and add a path to the boost library root (in my case C:\Program Files (x86)\Boost_1_53).
  2. Include a .hpp file in your sources, like #include <boost/lexical_cast/lexical_cast_old.hpp>

If you're using non headers-only libraries you should also add path to Boost libraries in Project propertiesLinkerGeneralAdditional Libraries Directories.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
kvorobiev
  • 4,801
  • 4
  • 27
  • 33
1

In Visual Studio 2012, right-click on your project and select "Properties".

In the properties dialog, select "Configuration Properties" and then "VC++ Directories".

You will need to add the Boost include path to the "Include Directories" list.

If you're using all header-only libraries then you're done. Otherwise, you will need to add the Boost library path to "Library Directories".

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Ferruccio
  • 93,779
  • 37
  • 217
  • 294
0

For example:

  1. Boost library - c:\boost\boost_1_58_0 (run booststrap.bat and b2 as administrator).
  2. Add strings $(THIRD_PARTY)\boost\boost_1_58_0\include and $(THIRD_PARTY)\boost\boost_1_58_0\ to VC++ DirectoriesInclude Directories
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123