c++ - 即使包含文件也编译错误

标签 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->()'
我已经包含了正则表达式,这是什么原因引起的?

最佳答案

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

关于c++ - 即使包含文件也编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63293871/

相关文章:

c++ - 是否有一个普遍接受的习惯用法来指示 C++ 代码可以抛出异常?

c++ - 使用 sendfile()/fcopyfile() 从共享内存映射对象复制数据

c++ - 接口(interface)和多态的区别

c++ - 在 boost geometry c++ 库中我添加的点的顺序有关系吗?

C++打印模板容器错误(错误: ambiguous overload for 'operator<<' ) understanding?

c++ - 无法将 'this' 指针从 'const Line' 转换为 'Line &' 解释?

c++ - 使用 C++ constexpr 可以创建符号重复吗?

c++ - 使用 gcc 的别名模板替换和推断失败

compiler-errors - 为什么在编译时MinGW无法识别我的目标文件?

c++ - 复制构造函数的 const 正确性问题?