How do I include Boost libraries? - c++

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.

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:
Go to Project properties → C/C++ → General → Additional Include Directories, and add a path to the boost library root (in my case C:\Program Files (x86)\Boost_1_53).
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 properties → Linker → General → Additional Libraries Directories.

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

For example:
Boost library - c:\boost\boost_1_58_0 (run booststrap.bat and b2 as administrator).
Add strings $(THIRD_PARTY)\boost\boost_1_58_0\include and $(THIRD_PARTY)\boost\boost_1_58_0\ to VC++ Directories → Include Directories

Related

LNK1104 for unneeded library

I am trying to include the Boost Library in my OpenFrameworks project, in particular it is
When I add the boost root directory to the Additional Include Directories of a new project, I see the error LNK1104 cannot open file 'libboost_filesystem-vc141-mt-gd-x32-1_72.lib', although I don't even need the filesystem library.
However, when I added the boost root directory to the Additional Include Directories of a freshly create c++ console project, the error does not show, and I can make use of the library without problems.
Runtime Library is /MDd.
What might cause this problem? A broken build of boost?
One
Taken from the comments to the question. Although this is unusual it could be that a header in one of the dependencies of your project has the same name as a header in the filesystem library. And since you put boost first in the Additional Include Directories the boost header was included instead of a header from a different library. By default with Visual Studio boost automatically inserts link commands using a #pragma comment(lib, libname) so including this header will cause a link dependency.
A solution to try in this case is to move boost to the end of the Additional Include Directories so when the compiler searches for the header it will find the one from the previous dependency first.

Boost C++ Libaries in Visual Studio 2017 C++ Project - "Cannot open include file"

I'm trying to add the Boost C++ Libraries to my C++ project created with Visual Studio 2017.
I have followed the instructions here.
When that didn't work I tried the advice in this post. Neither solutions worked for me.
What I have done:
Downloaded boost_1_69_0-msvc-14.1-64.exe from this precompiled boost libraries page
Installed to D:\local\boost_1_69_0
In my project I added D:\local\boost_1_69_0 to Properties > VC++ Directories > Include Directories and added D:\local\boost_1_69_0\lib64-msvc-14.1 to Properties > VC++ Directories > Library Directories
I have my project set to x64 and the above settings were set in the x64 configuration
When I try to build my project I get this error:
Error C1083 Cannot open include file: 'boost/regex.hpp': No such file or directory
Which points to this line of code in one of my .cpp files:
#include <boost/regex.hpp>
Please go to D:\local\boost_1_69_0 folder and see if you have a sub-folder named include in there. If you do, then instead of D:\local\boost_1_69_0 you need to set D:\local\boost_1_69_0\include in Properties > VC++ Directories > Include Directories
In other words, try to find the file you are including on your hard drive. Look at the full path to the file. Compare that full path with the path you added to the list of include directories (Properties > VC++ Directories > Include Directories) concatenated with the relative path you provided just before the filename in your include directive (boost). See if the two are the same.
If that does not help, then make sure you changed list of include directories for the same build configuration as you are attempting to build (if you build Debug, make sure you changed configuration for Debug too). Since VS 2015 IDE stopped making sure the two are selected in sync, which is annoying.
If your files are copied, then you have to compile the regular library.... If the same version of the compiler copies the machine.
Found out it was failing because I had included the same .cpp file which has the boost include into my unit test project which did NOT have the Include/Library folders set. The settings in my original question work now.

Troubles switching from VC++ Directories to User Macros for Boost

Good day,
I have previously successfully used boost in Visual Studio 2010 by using Include and Library Directory paths under VC++ Directories in project settings. However not long ago I have been forced to switch to using "User Macros" to do the linking due to a new lecturer where I study.
I had no issues moving my other libraries to using User Macros, I simply used the same include and library path when creating the macros. Boost however is not playing so nice. While having the boost folder linked under VC++ Directories it worked as it should, but when I try moving the include and library paths to User Macros, Visual Studio refuses to recognize the path and I'm getting the following normal error:
error C1083: Cannot open include file: 'boost/filesystem.hpp': No such file or directory
When I move back to using VC++ Directories it works again.
Is there any simple explanation why boost doesn't want to be linked with macros, while all my other libs are totally fine with it? The other libraries include DevIL, SDL, glew, glm and assimp as of now.
I seem to have found the solution. I had to add my boost macro names under "Project settings - C/C++ - Additional Include Directories" and "project settings - linker - Additional Library Directories".
Somehow the other macros I have made have appeared in those two lists automatically, and I'm not sure why the boost macros were not added automatically too. Now it's working as it should though, so I'll just go with it like this.

How to make the visual studio 2008 IDE look at the right place for header files. Compiling Qt/C++ program

I am building an app on Qt 4.6.2 using visual studio 2008. I need to include the header <QtGui\QDir>.
Problem : The QDir header includes several headers. Once of them is qfile.h. Now the ide/compiler is unable to include this file and the error I get is this
c:\devprojects\myprojects\nttoolkit\trunk\external\qt\include\qtcore../../src/corelib/io/qfile.h(45)
: fatal error C1083: Cannot open
include file:
'Qt/include/QtCore/qiodevice.h': No
such file or directory
I cannot change the path in the file qfile.h since it is an external file to my project. How do I get it working.
Thanks.
The various places the preprocessor searches for include files is described in the Remarks section here.
Typically for an "SDK" like Qt people will change their VC++ Directories, Projects, Options under Tools | Options | "Projects and Solutions" | "VC++ Directories" so that the Include Files and Library Files lists include suitable Qt directories. That way, when the preprocessor searches for Qt include files, it will look in the right places and when the linker looks for .LIB files it will find them also.
One downside to changing those lists is that they apply to all projects built from that version of Visual Studio. That can be a pain in the neck if you have different projects that use different versions of an SDK. In those sorts of situations one solution is to create environment variables called INCLUDE and LIBPATH and then launch devenv with the /useenv switch to override the VC++ Directories settings from Tools | Options.
Finally, a third option is to provide the additional include and library folders via the project properties. In Project | Properties | C++ | General the first property is "Additional Include Directories". Values placed there are passed to the preprocessor via the /I switch. Similarly the Project | Properties | Linker | General tab has an "Additional Library Directories" property which gets passed to the linker via the /LIBPATH switch.
This third option seems attractive because it lets you set these additional directories on a project by project basis. The downside is that it "hard-codes" some directory names in the project. That can be a real pain if you move the project to a new machine where the Qt files are in a different directory or when you have to move the Qt directories to a different hard-drive, etc.
In VS2010, I go to:
Project Properties -> VC++ Directories -> Include Directories
And set the location of directories containing headers I need to include. I don't currently have access to a VS2008 install, but I think there is a similar configuration option available.

How do I create a C++ library in VS 2008?

I am working in VS 2008 and have several C++ projects and want to build my own library to share across projects. The first project is called "Project 1".
I created the library as a separate Win 32 project, and chose DLL. I added a reference in Project 1 to the library using "Add reference". I also added an "Additional reference search path". I added #include "Library.h" to the top of the cpp file for Project 1.
However, I am getting the error: fatal error C1083: Cannot open include file: 'Library.h': No such file or directory.
How do I do this?
Thanks!
In Visual C++'s terms, referencing a project does not add it to include search path (this is a paradigm shift from .NET). Because in C++, include can do all sorts of things -- you can even #include <not_even_a_c_file.txt>, for example.
Anyway, the quick solution for you is to also add the include path to Project 1. You can find it under Project Properties > C++ > General. You need to add the path to Project 2 under "Additional Include Directories".
If the projects are in separate folders, you may have you do something like:
#include "../libproject/Library.h"