Boost Regex throwing an error - c++

I have the following error when I try to compile my code in g+ compiler using eclipse
In function `ZSt19__iterator_categoryIPKSsENSt15iterator_traitsIT_E17iterator_categoryERKS3_':
C:/Program Files (x86)/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_algobase.h:(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)]+0x22): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
All I have done is this statement
boost::regex re("\s+"); along with the header #inlucde
Could you kindly tell me how to proceed ?

It appears that you're not linking to the correct library. Most Boost libraries are header-only, so you don't need to do anything about them at link time. Boost::regex, however, is one of the few that requires that you link with a library along with giving the compiler the proper headers.
After you fix that, you'll want to re-check the escape in your string -- right now your passing "\s", which shouldn't be allowed (at a guess, you probably want "\s+" instead).

Related

Undefined reference errors in RTI DDS when using modern c++ API

I generated RTI code using:
/opt/rti_connext_dds-6.0.0/bin/rtiddsgen -d GENERATED_CODE_DIR -language C++11 -replace IDL_DIR
My CMake file:
link_libraries(gsl gslcblas nnz12 occi clntsh dl nddsc nddscpp2 pthread)
add_definitions(-DRTI -DRTI_64BIT -DRTI_LINUX -DRTI_UNIX -D_GLIBCXX_DEBUG)
include_directories(-isystem /opt/rti_connext_dds-6.0.0/include/ndds)
include_directories(-isystem /opt/rti_connext_dds-6.0.0/include/ndds/hpp)
include_directories(-isystem /opt/rti_connext_dds-6.0.0/include/ndds/hpp/rti)
include_directories(-isystem /opt/rti_connext_dds-6.0.0/include/ndds/hpp/dds)
Now when compiling, I am getting following errors:
undefined reference to `rti::domain::register_type_plugin(dds::domain::TDomainParticipant<rti::domain::DomainParticipantImpl>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, PRESTypePlugin* (*)(), void (*)(PRESTypePlugin*))'
undefined reference to `dds::core::PreconditionNotMetError::PreconditionNotMetError(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
Is there anything I am missing ?
The problem was due to ABI. I am using gcc10.2.
I solved the problem by adding definition:
_GLIBCXX_USE_CXX11_ABI 0
The problem was due to the difference in ABIs of RTI libraries and the occi.so.
Solved the problem by using occi_gcc53.so instead of occi.so library.

undefined reference to boost::filesystem::path_traits::convert

I am trying to compile a program using cmake, and am seeing the following linker error:
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log_setup.so:
undefined reference to
boost::filesystem::path_traits::convert(wchar_t const*, wchar_t
const*, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >&, std::codecvt<wchar_t, char, __mbstate_t>
const&)' /home/quant/bin/boost_1_61_0/stage/lib/libboost_log.so:
undefined reference to
boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry
const&, std::__cxx11::basic_string,
std::allocator >&)'
The linker command that ninja generated looks like this:
g++ -pthread -DBOOST_ALL_DYN_LINK
utility/test/CMakeFiles/utilityTest.dir/loadCSVTests.cpp.o
utility/test/CMakeFiles/utilityTest.dir/main.cpp.o
utility/test/CMakeFiles/utilityTest.dir/randomDeviceTests.cpp.o -o
utility/test/utilityTest -rdynamic
/home/quant/bin/boost_1_61_0/stage/lib/libboost_thread.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_program_options.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_serialization.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_unit_test_framework.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_system.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log_setup.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_filesystem.so
utility/lib/libutilityLib.a utility/testLib/libutilityTestLib.a
utility/lib/libutilityLib.a
/home/quant/bin/boost_1_61_0/stage/lib/libboost_thread.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_program_options.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_serialization.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_unit_test_framework.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_system.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_log_setup.so
/home/quant/bin/boost_1_61_0/stage/lib/libboost_filesystem.so
-Wl,-rpath,/home/quant/bin/boost_1_61_0/stage/lib
As you can see, I am linking against boost_filesystem and boost_system, so it's not the same problem as referenced on this SO post (and the many others like it).
I am using boost 1.61, which I compiled with gcc 5.3 (the same compiler as the one I'm compiling my program with).
What am I doing wrong?
I had a similar issue, this could be because of a new ABI which is introduced from gcc 5.1.
https://github.com/openframeworks/openFrameworks/issues/4203
I fixed mine by adding "add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)" to CMakeLists.txt

Undefined reference errors from an unneeded library

I'm getting some "undefined reference" errors in ld and am at a loss as to what's causing them.
My makefile builds several executables using commands like this:
g++ -ogui_program1 -Lpath/to/MyLibs gui_program1.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
g++ -ogui_program2 -Lpath/to/MyLibs gui_program2.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
g++ -ocli_program1 -Lpath/to/MyLibs cli_program1.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
g++ -ocli_program2 -Lpath/to/MyLibs cli_program2.o -lMyUI -lMyBusinessLogic \
-lMyUtil -lboost_regex
And so on. (Actually, there are quite a few more libraries than this, but this is the general idea.)
MyUI, MyBusinessLogic, and MyUtil are all dynamic libraries that I've already built. To make writing the makefile simpler, the same list of libraries is used for both GUI and command line programs, even though the command line programs don't need libMyUI.so.
One and only one of the command line programs is giving numerous errors about undefined references to Boost.Regex symbols when I try to link it, even though I'm linking -lboost_regex with every binary:
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)'
libMyBusinessLogic.so: undefined reference to `boost::cpp_regex_traits::toi(char const*&, char const*, int) const'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::match()'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher, std::allocator > >, std::allocator, std::allocator > > > >, boost::regex_traits > >::find()'
libMyBusinessLogic.so: undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)'
libMyBusinessLogic.so: undefined reference to `boost::re_detail::perl_matcher >, boost::regex_traits > >::match()'
Linking all other programs works fine. If I remove -lMyUI from the one command-line program, then it works fine, even though MyUI doesn't show up anywhere in the error list.
Why isn't ld finding Boost.Regex symbols, when I've added -lboost_regex to the end of the command? Why does removing a seemingly unrelated library fix it? Why do other programs link without any problems?
I've figured out at least most of the answer. Due to some sloppiness in my makefile rules, libMyUI.so was linked against boost_regex, but libMyBusinessLogic.so wasn't. I'm guessing that, as a result, linking MyUI caused boost_regex to get pulled in prematurely, before the linker knew all of the symbols that MyBusinessLogic would need from it.
As long as I'm consistent - either all of My*.so link with boost_regex, or none of them do - everything works. I'm not sure which of these solutions is most preferred, but at least I have a fix.

Compilation issue with boost library

I am trying to compile some source codes. However it is throwing some error related to boost library. Here is the error
undefined reference to `boost::re_detail::get_mem_block()'
main.cpp:(.text+0x40a6): undefined reference to `boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)'
main.cpp:(.text+0x40db): undefined reference to `boost::re_detail::put_mem_block(void*)'
main.cpp:(.text+0x430a): undefined reference to `boost::re_detail::put_mem_block(void*)'
main.o: In function `_ZN7Command12createVectorIdEEvRKSsRSt6vectorIT_SaIS4_EES4_.constprop.1207':
main.cpp:(.text+0x436e): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
main.cpp:(.text+0x439f): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
main.cpp:(.text+0x43d0): undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<
I have the boost regex library installed in my system and I have given the path to the library using -L option and specified the library using -lboost_regex option as well. What could be the issue?
It does find the library. But still throwing an error
I met the same problem, and it has been solved. So maybe you had installed an older version of boost before, and the linker linkes the older version.
Try to remove all installed boost library, and reinstall the boost library, your problem will be solved.

boost's regex won't compile

I am using boost 1.45.0 on Ubuntu with Code::Blocks as my IDE, and I can't get basic_regex.hpp to compile. I'm pretty sure I set up boost correctly, because I can compile programs using boost::format without any errors. But I'm getting this annoying error, and I don't know how to get rid of it.
The code that is provoking the error:
boost::regex e("\"http:\\\\/\\\\/localhostr.com\\\\/files\\\\/.+?\"");
Compiler output (GCC):
obj/Debug/main.o
In function `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)'
/home/neal/Documents/boost_1_45_0/boost/regex/v4/basic_regex.hpp|379|
undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'|
||=== Build finished: 1 errors, 0 warnings ===|
Did I miss a step when setting up boost, or should I downgrade to another version of boost?
This looks like a linker error. boost::regex is not a header only library so you need to pass -lboost_regex with correct -L/path/to/boost/lib to linker.
Boost::Regex has some code that lives in a separate library (libboost_regex.so). To link against it, add -lboost_regex to the GCC commandline you're using.
Depending on your install, that might be libboost_regex-mt.so. In that case, you'll need to use -lboost_regex-mt on your command line. (The MT stands for mutlithreaded.)
That's a linking error rather than a compiler error. You need to explicitly link against Boost's regex library.
g++ program.cpp -lboost_regex -L/path/to/boost/lib