How to start with boost

I downloaded boost ver 1.59.0 and placed the directory in C:\boost. I ran the bootstrap and .\b2 and then added

C:\boost\boost_1_59_0;C:\boost\boost_1_59_0\stage\lib;

to the path variable.
I then try to use it with

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <boost/filesystem.hpp>

namespace boostfs = boost::filesystem;

int main(int argc, char *argv[])
{
	if (argc <= 2)
	{
		std::cerr << "Usage: "<<argv[0]<< " <filename>"
		<<std::endl;
		return 1;
	}

	bostfs::path p(argv[1]);

	if(boostfs::exists(p))
	{
		std::cout<,"File "<<p<<" exists."<<std::endl;
	}
	else
	{
		std::cout<<"File "<<p<<" does not exist."<<'\n';
	}

	return 0;
}


However when I try and compile a program in the command line with "cl /EHsc boosttest.cpp i get the error
"cannot open include file: 'boost.filesystem.hpp': No such file or directory
Last edited on
If that's the exact error message you get, it doesn't match the source you provided.

Also, I wouldn't imagine most compilers use the path environmental variable for checking includes.

Did you visit: http://www.boost.org/doc/libs/1_59_0/more/getting_started/index.html ?
Last edited on
Yes, it just says

The path to the boost root directory (often C:\Program Files\boost\boost_1_59_0) is sometimes referred to as $BOOST_ROOT in documentation and mailing lists .

To compile anything in Boost, you need a directory containing the boost\ subdirectory in your #include path. Specific steps for setting up #include paths in Microsoft Visual Studio follow later in this document; if you use another IDE, please consult your product's documentation for instructions.


I took that to mean to set the path environment to C:\Program Files\boost\boost_1_59_0. Also, I usually just compile from developer command line after writing program in a text editor. I have Visual Studio but dont use it
Last edited on
Also, I usually just compile from developer command line after writing program in a text editor.

Then, ensure the appropriate directory is added to the #include path and the path to the library is passed on to the linker via command line arguments (or it might be a good time to start using a make file to automate things.) Unfortunately, the environment path has nothing to do with it.
So just to clarify, If i download boost ver 1.59.0, I just have to place the files somewhere and then put the directory in the include path. So for me I would just have to do something like
 
#include <C:/Program Files/boost/boost_1_59_0/boost/filesystem.hpp> 


filesystem is one of the ones where I have to build the libraries right? I tried following the getting started page and typed (from section 5.1)

bootstrap
and then
.\b2

into the command prompt. When it was done, it told me to put C:\boost\boost_1_59_0;C:\boost\boost_1_59_0\stage\lib; into the path environment.

However I still cant get it to work.
So just to clarify, If i download boost ver 1.59.0, I just have to place the files somewhere and then put the directory in the include path. So for me I would just have to do something like
#include <C:/Program Files/boost/boost_1_59_0/boost/filesystem.hpp>

No. You need to put the directory in the include path, not put the full path in the include directive.

filesystem is one of the ones where I have to build the libraries right?

Yes. You must supply the name of the library and add the appropriate path to the library path.

How are you invoking the compiler? With what options?

Im on windows and I just run the developer prompt from visual studio 2015

I just cd into working directory and run it with

cl /EHsc boosttest.cpp

thanks for responding

Edit: I found this video (https://youtu.be/P_wWshgf3U4) and got it working in visual studio
Last edited on
Topic archived. No new replies allowed.