1

When I compile my C++11 on Unix I get the following error: (Even though it works fine on clion of my mac)

-bash-4.2$ g++ -std=c++11 -Wall -Werror -pedantic-errors -DNDEBUG main.cpp utilities.cpp utilities.h Graph.cpp Graph.h Exception.cpp Exception.h Edge.cpp Edge.h Calculator.cpp Calculator.h -o final
/tmp/ccLJAsey.o: In function `inner_load(int, std::string&, Calculator&)':
Calculator.cpp:(.text+0x13aa): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> >::regex_iterator(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, std::basic_regex<char, std::regex_traits<char> > const&, std::bitset<11ul>)'
Calculator.cpp:(.text+0x13b9): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> >::regex_iterator()'
Calculator.cpp:(.text+0x13d2): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> >::regex_iterator(std::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> > const&)'
Calculator.cpp:(.text+0x13e6): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> >::operator->()'
Calculator.cpp:(.text+0x1419): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> >::operator*()'
Calculator.cpp:(.text+0x14ae): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> >::operator->()'
Calculator.cpp:(.text+0x14cd): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> >::operator->()'
Calculator.cpp:(.text+0x1533): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> >::operator->()'
Calculator.cpp:(.text+0x1552): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> >::operator->()'
Calculator.cpp:(.text+0x1586): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> >::operator->()'

I have included regex so what is causing this?

user4581301
  • 33,082
  • 7
  • 33
  • 54
  • 2
    These are linker errors. You've included all the headers you need, but a library that implements the header has not been provided to the linker. – user4581301 Aug 07 '20 at 01:21
  • 2
    Why are `*.h` header files being compiled? – Eljay Aug 07 '20 at 01:22
  • @user4581301 I moved to use g++5.5 while it fixed the error still I am getting the following one: ./final: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./final) what does it mean? –  Aug 07 '20 at 01:22
  • 1
    Groovy. You just did what I was about to suggest. Early Regex implementations were goofy as hell. See if you can get even more up to date. Most recent GCC is 10.2. As for the new error, I'm not familiar with it. The code you're building with the new compiler may be trying to run against the old libraries or some other silliness. You may have to statically link the Standard library in. – user4581301 Aug 07 '20 at 01:28
  • See if this question matches your problem: https://stackoverflow.com/questions/19386651/how-to-fix-usr-lib-libstdc-so-6-version-glibcxx-3-4-15-not-found – user4581301 Aug 07 '20 at 01:28
  • @user4581301 `i found out after deleting line by line that the following causing the error, any ideas why? "std::set testme = {"print"};" –  Aug 07 '20 at 01:45
  • I have it in .h folder –  Aug 07 '20 at 01:46
  • `std::set` might not be supported by your version of g++. –  Aug 07 '20 at 02:10
  • It is supported –  Aug 07 '20 at 02:19
  • Your edit to the question made vonbrand's answer completely incoherent, so I've rolled back. When you change a question that much you need to ask a new question. – user4581301 Aug 07 '20 at 15:41
  • That said, this is something in the build tools or at runtime looking checking to make sure the Standard Library implementation the program will find when it looks for the dynamically linked library matches the Standard Library implementation expected by the code. You upgraded your compiler tools, but the rest of the system doesn't know this and is still operating off of the old libraries. Replacing the old libraries with the new ones will break all of the programs compiled to expect the old libraries, so welcome to DLL Hell. You'll need to statically link and remove the dependency on the DLL. – user4581301 Aug 07 '20 at 15:44

1 Answers1

1

Remember that C++' #include <regex> (or anything else, for that matter) just includes the (text, source code) file /usr/include/.../regex /(the ... will depend on your exact installation) into the file being cpompiled. If you take a peek a those files, they usually contain declarations of classes, functions, templates, and assorted #defines. The code implementing all that is elsewhere. Most of the stuff in the standard header files is in the standard C++ library, and when linking the compiler automatically adds it in. If it isn't part of the standard pieces, you might have to add additional libraries to the link step. What is included by default is (somewhat) up to the compiler, And it is also possible that one compiler places the full implementation into the header file (via inlinefunctions, macros and stuff), while another places it in the standard library or a separate library.

vonbrand
  • 11,412
  • 8
  • 32
  • 52
  • May you kindly take a look at the new error message? –  Aug 07 '20 at 01:32
  • @dure, please don't change the question. Ask a new one. This is probably due to having pieces compiled with the old compiler in the mix. Clean up and compile everything from scratch. – vonbrand Aug 18 '20 at 13:23