administration mode
Pssst...Ferdy is the creator of JungleDragon, an awesome wildlife community. Visit JungleDragon


Article: Using Boost C++ libraries in Eclipse »

FERDY CHRISTANT - AUG 29, 2007 (06:11:24 PM)

Every now and then I have a play with C++ on my Ubuntu laptop. I'm not particularly experienced in C++, but enjoy its raw power, portability and complexity. I still have the ambition of building something cool with OpenGL one day, but finding the time is problematic.

Anyway, for a very simple test program I wanted to list the files in a directory using C++. Surprisingly, there is not a built-in way to do this in a portable way in C++. Instead, one has to rely on external libraries. In my search to do this as standardized as possible, I ended up at Boost, a large collection of reusable libraries.

This post lists the steps to install Boost and make use of it in Eclipse under Ubuntu, it is likely to work in a similar way in other distributions and even on Windows.

In Ubuntu, version 1.33.1 of Boost is included in the package manager, whilst the current version is 1.34.1. We now have two options, installing the latest version manually, or using the package manager to install the 1.33.1 version. I went for the 1.33.1 version, because I am lazy and prefer using stable libraries that are packaged for my distrubution. To install 1.34, see the Getting Started section on the Boost site.

Boost consists of a general library and a number of individual libraries that you may or may not need. In my case I needed the general library and one specific library, the file system library. In the Synaptic package manager I therefore selected the following packages and marked them for installation:

  • libboost-dbg
  • libboost-dev
  • libboost-doc
  • libboost-filesystem1.33.1
  • libboost-filesystem-dev

After hitting "apply", the packages are downloaded and installed. With the installation done, it is time to put it to the test. In Eclipse, create a new managed C++ project, and add a source file to it called "main.cpp". Next, we paste example code in the source file. Note that the Boost website contains an example that lists the files in a directory. This example will work if you installed Boost 1.34.x, but not if you installed 1.33, like I did. The 1.33 example is part of the 1.33.1 download. Once you have the correct sample code, paste it into the new source file you created.

Almost done. The last step to perform is to link to the file system library. You can use of the general library functions of Boost without explicit linking, but the individual libraries you must link to from your project. Luckily, this is easy. Im Eclipse, right-click on your project and go to Properties. Next, open the Libraries section under GCC C++ Linker. In the Libraries (-l) panel add an entry with the value "boost_filesystem" and click OK.

Done! Boost is installed and you have set up your project in Eclipse successfully. After saving main.cpp, your project is built automatically, unless you disabled this in Eclipse. Finally, test the program by initating it from the command line, and passing it a file path. This should result in a directory listing of the speccified path. Here is an example run:


Whilst this may sound like a lot of work for listing a directory, do know that this is just a simple example to test Boost. Once properly configured, Boost opens up a world of useful, portable functionality.  

Share |

Comments: 13
Reviews: 8
Average rating: rating
Highest rating: 5
Lowest rating: 5


SEP 6, 06:38:27 AM

comment » Thanks. You article helped me lots. 18 «


MAY 30, 2008 - 17:51:13

comment » Very nice article. I finally managed to make Boost Filesystems works :D Thx «


JUN 21, 2008 - 08:10:31 AM

comment » I had a problem with Boost's regex library, but thanks to this description I could solve it. Thanks. «


OCT 6, 2008 - 07:45:50 AM

comment » Thanx! Very useful! «


MAY 13, 2009 - 02:37:30 AM

comment » Thanks. THe article was really helpful «


MAY 18, 2009 - 04:59:04 PM

comment » it worked for the filesystem lib, but i'm trying to do it for the asio lib ... i put boost_asio, but it didn't worked. Any help? «


SEP 29, 2009 - 07:24:18 PM

comment » Just installed the 1.37 via apt-get, I had the follow to the compiler line to get it to work.


Thanks for the great article it made it possible to find my error.

thanks «

COMMENT: DC rating

JAN 27, 2010 - 09:47:12 PM

comment » Your link to the example code gives some errors for those using the boost 1.34.1 with Ubuntu 8.04, the correct link is this

I was able to use boost with your little bit of help. Thanks! «


JUN 8, 2010 - 18:51:21

comment » Thanks a lot, particularly for the hint about the GCC C++ Linker! Now it works. «

COMMENT: AA rating

OCT 14, 2010 - 11:02:51 AM

comment » thanq for ur article «


OCT 18, 2010 - 12:36:30 PM

comment » VERY HELPFUL 18 «


JUL 2, 2011 - 18:07:43

comment » Sitting there about an hour, wondering why always getting:

filesystem.cpp:(.text+0x29): undefined reference to `boost::system::get_system_category()'

filesystem.cpp:(.text+0x35): undefined reference to `boost::system::get_generic_category()'

filesystem.cpp:(.text+0x41): undefined reference to `boost::system::get_generic_category()'

filesystem.cpp:(.text+0x4d): undefined reference to `boost::system::get_generic_category()'

filesystem.cpp:(.text+0x59): undefined reference to `boost::system::get_system_category()'

collect2: ld returned 1 exit status

-l boost_filesystem ist is..

Thank you !! «


NOV 3, 2014 - 11:15:36 AM

comment » VERY HELPFUL

face same issue as MARIO add boost_filesystem and now it work ! «

Was this document useful to you?
rating Awesome
rating Good
rating Average
rating Poor
rating Useless
required field
required field HTML is not allowed. Hyperlinks will automatically be converted.