2

I really want to get in to using the boost library and I am having trouble "installing" it.

I want to be able to access the functionality by saying

#include <boost/signals2/signal.hpp>

then g++ filename.cpp.

instead of having to write

#include "boost/signals2/signal.hpp"

and have chunks of boost in my local directory.

Is there a way in which I can set up boost such that this works? I have downloaded the boost library and extracted it to /usr/local.

kenba
  • 4,303
  • 1
  • 23
  • 40
  • Possible duplicate of [How do I include a path to libraries in g++](https://stackoverflow.com/questions/6141147/how-do-i-include-a-path-to-libraries-in-g) – newkid Mar 05 '19 at 20:19

2 Answers2

4

The easiest way to use boost in Fedora is to simply install the boost-devel package, e.g.:

sudo dnf install boost-devel

It will install the boost include files in /usr/include and the boost library files in /usr/lib64.
I.e. the default include and library paths for gcc on Fedora, so gccwon't need the -I and -L options.

The installed version of boostdepends on your version of Fedora, see RPM resource boost-devel.

kenba
  • 4,303
  • 1
  • 23
  • 40
  • I did this, now g++ filename.cpp throws a TON of undefined references. When installing boost this way what exactly do I type in the command line? g++ -lboost filename.cpp doesnt work either, cannot find -lboost –  Mar 06 '19 at 16:56
  • You need to add `-l` arguments to `gcc` for the missing boost libraries. It's not as simple as just -lboost. You can ls `/usr/lib64` to see which `libboost` files were installed. – kenba Mar 06 '19 at 18:20
1

This is because you are not passing the include directory to g++. Your compiler command should be:

g++ filename.cpp -I /path/to/boost/headers

Sometimes it may happen that a few headers are not found. Then you must include multiple directories where you may find all the headers. To include multiple directories see this answer.

Don't forget to link the corresponding library as well! You can see this answer on how to do it.

Another solution would be to install boost with brew or a package manager at the default location which is included in C_INCLUDE_PATH such as /usr/local. However, if you intend to work with OR have multiple versions of boost, you quickly run into problems.

newkid
  • 1,368
  • 1
  • 11
  • 27
  • https://www.boost.org/doc/libs/1_48_0/libs/locale/doc/html/hello_8cpp-example.html This file with g++ -I/usr/local/boost/include -L/usr/local/boost/libs -lboost myfirstboost.cpp throws boost/locale.hpp: No such file or directory #include –  Mar 06 '19 at 07:10
  • Its probably because, boost can't find that header and then you have to include several directories and link several libraries. See edit to answer. – newkid Mar 06 '19 at 07:57