0

I used wregex as the following C++ codes. But it does not work, could you help me? any advices are welcome.

#include <boost/regex.hpp>
namespace abc
{
    int ClassName::fun1()
    {
        wstring wp1 = _String2Wstring(p1); // This a function defined by myself.
        boost::wregex wreg(wp1,boost::regex::perl|boost::regbase::icase);
        ......
    }
}

I can compile a .so file successfully in centos 7. But when I start my application. I get the following message in the log file by the website http://demangler.com/

undefined symbol: boost::basic_regex<wchar_t, 
boost::regex_traits<wchar_t, boost::cpp_regex_traits<wchar_t> > 
>::do_assign(wchar_t const*, wchar_t const*, unsigned int)

And if delete the following code, I can start my application. So I think the error is from this code. But I am confused to find the answer. Thanks.

boost::wregex wreg(wp1,boost::regex::perl|boost::regbase::icase);
taichi_tiger
  • 809
  • 1
  • 7
  • 18
  • 1
    The error you see is a *linker error*. It happens because you didn't include a boost regex library in your build. – john Sep 20 '18 at 09:01
  • 1
    See https://stackoverflow.com/questions/559179/linking-to-boost-regex-in-gcc/559191#559191, https://stackoverflow.com/a/21863253/3832970, https://stackoverflow.com/a/11985138/3832970 – Wiktor Stribiżew Sep 20 '18 at 09:02
  • Not that `_String2Wstring` is a reserved name in global namespace - https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier – sehe Sep 20 '18 at 16:33

1 Answers1

0

I think you are not saying to your linker to link against boost_regex. If you are using GCC, add linker flag -lboost_regex. Other compilers require similar flags.

Stefano
  • 3,981
  • 8
  • 36
  • 66