Author Topic: Adding a library to C++  (Read 13550 times)

optimus_prime

  • Guest
Adding a library to C++
« on: November 20, 2012, 12:20:52 pm »
Hi,
I started using Code::Blocks for one of my C++ projects. I had a requirement to use the very popular Boost libraries in project. I'm on Ubuntu 12.10 and had installed Codeblocks manually via terminal with the instruction on Wiki. The compiler on the machine is `gcc`.


To use Boost, I tried to manually download and install the libraries. Boost has some of the libraries which do not require to be built and can be simply be used by typeing the name of the header file.
After the manual install, when I included any Boost specific library such as #include <boost/regex.hpp>, I started getting errors with any of the Boost libraries (whether or not they required to be built prior to use)

Subsequently, I installed the libraries via Ubuntu repository by `sudo apt-get install libboost-all-dev`, after which the installation successful message was shown on ther terminal. Currently, I can include the header files which do not need to built without any problem. However, when I try to include the libraries which do require to be built, I stumble upon the errors again.

Quote
/usr/include/boost/system/error_code.hpp|214|undefined reference to `boost::system::generic_category()'|

I tried asking around and got to know that this is a linker error and I had to use something like `-lboost_system` to be added to the compiler. I am not exactly sure where do I add the above `linker flag` but I tried adding it at Settings -> Compiler and Debugger -> Linker Settings -> Other Linker Options. and the errors still don't go away.

I am stuck with this linker error for long and could really use some help here with adding these flags and getting Boost libraries running on Codeblocks. Thanks in advance.

Offline Martin K.

  • Multiple posting newcomer
  • *
  • Posts: 86
Re: Adding a library to C++
« Reply #1 on: November 20, 2012, 02:09:08 pm »
go to the project node in the projects view, right mouse click, "build options...", Linker settings, Link libraries, add "boost_system"

Martin