Yotam
Yotam

Reputation: 10685

how to use boost in linux

I'm trying to use the shared pointer class(?) from boost. I have downloded boost and extracted it to a subfolder(boost) in my source folder (src). I have then added a line:

#include "boost/shared_ptr.hpp"

When I try to compile, I get an error:

error: boost/smart_ptr/shared_ptr.hpp: No such file or directory

What do I have to add for the program to compile?

I'm working on a scientific linux machine without root privliges

Upvotes: 5

Views: 5529

Answers (3)

Jason
Jason

Reputation: 32510

You will need to, with g++, add the directory as a compile option like g++ -I./boost ... or basically add as a command line option -I directly followed without a space by the relative or absolute path where you have installed your boost library. Keep in mind also for future reference that some elements of boost, like the threading library also require some libraries to be linked against, and you will have to also include those file-paths at compile time using the -L option ... that isn't the case with boost::shared_ptr, but just giving you a head's up.

Upvotes: 12

Tobi
Tobi

Reputation: 81663

Assuming you have installed boost to some subdirectory of your home directory, you'll need to do one of these to specify where the compiler should look for the boost header files:

  • add a -I flag to the compiler command line (GCC docs)
  • set the CPLUS_INCLUDE_PATH environment variable (GCC docs)

Upvotes: 5

Nemanja Trifunovic
Nemanja Trifunovic

Reputation: 24561

You can add gcc -I option. Documentation.

Upvotes: 2

Related Questions