即使包含文件也编译错误

时间:2020-08-07 01:18:29

标签: c++ c++11 compiler-errors compilation

当我在Unix上编译C ++ 11时,出现以下错误:(即使在我的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->()'

我包含了正则表达式,是什么原因引起的?

1 个答案:

答案 0 :(得分:2)

请记住,C ++'#include <regex>(或其他任何原因)仅包含文件(文本,源代码)/usr/include/.../regex /(...取决于您的确切安装)放入要cpompiled的文件中。如果您看一下这些文件,它们通常包含类,函数,模板和各种#define的声明。实现所有其他内容的代码。标准头文件中的大多数内容都在标准C ++库中,并且在链接编译器时会自动将其添加到其中。如果它不是标准部分的一部分,则可能必须在链接步骤中添加其他库。默认情况下包含的内容(某种程度上)由编译器决定,并且也有可能一个编译器将完整的实现(通过inline函数,宏和东西)放置在头文件中,而另一个则将其放置在头文件中。标准库或单独的库。

相关问题