C++ tips: using external libraries in gcc project

Here I will show how to use external libraries like boost in your project and compile it using gcc. I will show it on Ubuntu OS.

First install boost on Linux

sudo apt-get install libboost-all-dev

Now create some C++ script with boost headers

#include <iostream>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
int main()
{
}

And compile with necessary library flags

g++ -o test_boost test_boost.cpp -lboost_system

Let’s try boost::format

int main()
{
unsigned int arr[5] = { 0x05, 0x04, 0xAA, 0x0F, 0x0D };

std::cout << boost::format("%02X-%02X-%02X-%02X-%02X")
% arr[0]
% arr[1]
% arr[2]
% arr[3]
% arr[4]
<< std::endl;
}

Output:

05-04-AA-0F-0D

--

--