9

I'm trying to get the Boost library working in my C++ projects in Eclipse. I can successfully build when using header-only libraries in Boost such as the example simple program in the "Getting Started" guide using the lambda header.

I cannot get my project to successfully link to the regex Boost library as shown later in the guide. Under my project properties -> c/c++ build -> settings -> tool settings tab -> libraries, I have added "libboost_regex" to the Libraries box, and "C:\Program Files\boost\boost_1_42_0\bin.v2\libs" to the Library search path box since this is where all the .lib files are. I've even tried adding "libboost_regex-mgw34-mt-d-1_42.lib" to the libraries box instead of "libboost_regex" since that is the exact file name, but this did not work either.

I keep getting an error that says "cannot find -llibboost_regex" when I try to build my project. Any ideas as to how I can fix this?

Edit: on Windows XP, using mingw, and I have tried "boost_regex" as well..

MahlerFive
  • 5,159
  • 5
  • 30
  • 40
  • Shouldn't it be -lboost_regex? – pau.estalella Mar 25 '10 at 22:01
  • 2
    What platform are you on? What compiler/linker are you using? – Björn Pollex Mar 25 '10 at 22:04
  • Yes I built boost using bjam as described in the getting started guide. I know this worked since the .lib are now present. For example the regex file is in C:\Program Files\boost\boost_1_42_0\bin.v2\libs\regex\build\gcc-mingw-3.4.2\debug\link-static\threading-multi, similarly there is a release folder as well as the debug folder – MahlerFive Mar 25 '10 at 22:29

3 Answers3

19

I just went through the whole process of installing MinGW, compiling boost and installing Eclipse CDT and I'm able to compile simple programs using boost:regex. I'll write down all the steps. I hope that can be of help.

I've installed MinGW and MSYS in their default location.

Here are the step I took to build boost:

  • Download boost-jam-3.1.18-1-ntx86.zip from http://sourceforge.net/projects/boost/files/boost-jam
  • Put bjam.exe somewhere in your PATH
  • Unpack boost in C:\mingw\boost_1_42_0
  • Open an msys terminal window and cd /c/mingw/boost_1_42_0
  • In the boost directory run bjam --build-dir=build toolset=gcc stage

To configure Eclipse:

  • Add CDT to Eclipse 3.5 from the update site
  • Create a new C++ project
  • Under the Project menu select properties
  • Make sure the configuration is Debug [Active]
  • In "C/C++ General" > "Paths and Symbols"

    • Under the Includes tab select the GNU C++ language and add C:\MinGW\boost_1_42_0
    • Under the Library Paths tab add C:\MinGW\boost_1_42_0\stage\lib
  • In "C/C++ Build" > "Settings"

    • Select MinGW C++ Linker > Libraries
    • Click on the add button for Libraries (-l)
    • Type libboost_regex-mgw34-mt-d (without the .lib)

You can then go through the same steps for the Release configuration but use libboost_regex-mgw34-mt instead. Also make sure your source files include <boost/regex.hpp>

Alex Jasmin
  • 39,094
  • 7
  • 77
  • 67
  • 1
    Thanks a lot! I changed the library paths directory to the stage\lib directory and added the libboost_regex-mgw34-mt-d and it worked! – MahlerFive Mar 26 '10 at 03:18
  • 1
    I found the step-by-step on this very helpful for the eclipse side. I had to use it in combination with this other question to help me through the most current directory structure and build process for boost: http://stackoverflow.com/questions/5299468/unable-to-build-boost-libraries-with-gcc (The answer is 7 yrs old, so no complaint. Just an update!) – Brick Mar 11 '17 at 22:55
7

To link to boost library in eclipse you need to set both the eclipse's project library path(the one with the -L) and the name of the library(the one with the -l).

The prefix 'lib' and the extension of the library's name must be removed:- eg: libboost_regex.a should be specified as boost_regex.

erzam
  • 71
  • 1
  • 1
  • 1
    Thanks! I was having a nghtmare on mac os x with this. Ended up just entering "boost_system" for the -l and my -L pointing to "bin.v2/libs". – span Feb 18 '12 at 15:35
  • 1
    this should be the right answer. it solves the problem on all operating systems and is version independent. – Sahil Sachdeva Jul 03 '13 at 14:36
0

I believe your lib path is pointing to the wrong place. The libs will be installed to:

boost_install_dir\boost_1_42\lib

I think the default boost_install_dir is "C:\Program Files\Boost" (not sure because I don't use the default install directory).

zdan
  • 28,667
  • 7
  • 60
  • 71
  • 1
    I have a "libs" directory, but not "lib" in my boost directory, but this does not actually contain the compiled files which are in the bin.v2\libs directory – MahlerFive Mar 26 '10 at 03:11