Undefined reference to boost::locale:conv::between

boost, c++, locale

Solution

Boost locale is not a header-only library, it has an actual library that you need to link with. Adding following flag to LDFLAGS helps:

-lboost_locale

Problem

I am trying to follow the answer to my previous question and use `boost::locale::conv::between` to get a UTF-8 string from `vector<char>` containing UTF-16 data. My code is pretty much as in the answer (with some differences in how I get the `char *`: ``` char in[length + 1]; //... populate in with my source data in[length] = '\0'; std::string out = boost::locale::conv::between((const char*)in, std::string("UTF-8"), std::string("UTF-16")); ``` This compiles fine, but during linking I get error ``` In function `boost::locale::conv::between(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::locale::conv::method_type)': /usr/local/include/boost/locale/encoding.hpp:186: undefined reference to `boost::locale::conv::between(char const*, char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::locale::conv::method_type)' ``` This doesn't look right to me. On possibility I could think of is that I had boost 1.50 installed, so I installed latest 1.55 release - yet I get the same error.

Original source