【发布时间】:2026-02-23 00:30:01
【问题描述】:
当我在 Unix 上编译我的 C++11 时,我收到以下错误:(即使它在我的 mac 的 clion 上运行良好)
-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->()'
我已经包含了正则表达式,这是什么原因造成的?
【问题讨论】:
-
这些是链接器错误。您已经包含了所有需要的头文件,但尚未向链接器提供实现头文件的库。
-
为什么要编译
*.h头文件? -
@user4581301 我改用 g++5.5,虽然它修复了错误,但我仍然收到以下错误:./final: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21'未找到(./final 要求)是什么意思?
-
时髦。你只是做了我要建议的事情。早期的 Regex 实现非常愚蠢。看看您是否可以获得更多最新信息。最新的 GCC 是 10.2。至于新的错误,我不熟悉。您使用新编译器构建的代码可能试图针对旧库或其他一些愚蠢的东西运行。您可能需要静态链接标准库。
-
看看这个问题是否符合你的问题:*.com/questions/19386651/…
标签: c++ c++11 compiler-errors compilation