gpt4 book ai didi

c++ - g++ 编译器如何包含 boost::regex

转载 作者:行者123 更新时间:2023-11-28 06:50:15 28 4
gpt4 key购买 nike

我已经安装了 boost,所以我正在尝试像这样运行编译器:g++ -LC:\MinGW\boost_1_55_0\stage\lib -lboost_regex-mgw49-mt-1_55 test.cpp

我的程序 test.cpp不是很复杂:

#include <iostream>         
int main()
{
std::cout << "Hello, world!" << std::endl;
boost::regex rex("[test]");
}

我当然失败了:error: 'boost' has not been declared .我不明白我必须在 test.cpp 中写什么#include <iostream> 旁边的文件? #include <boost>不起作用,我收到错误 fatal error: boost: No such file or directory . #include <boost/regex.hpp>也会产生此错误,可能是 #include <boost_regex-mgw49-mt-1_55> ?但它仍然不起作用。

最佳答案

您需要在主文件中包含 regex.hpp。您暗示您曾尝试过,但显然没有奏效。

确保 regex.hpp 是您告诉编译器它与您的搜索目录之一相关的位置。告诉编译器包含 boost/regex.hpp 是不够的,该文件必须实际存在于编译器正在查找的位置才能找到它。

你需要将该文件从你下载它的地方复制到编译器知道要查找它的地方。一旦你这样做,它应该会找到它并且错误应该会消失。

另请注意,这同样适用于您尝试链接的目标文件。如果链接器找不到该文件,您将在清除此编译器错误后收到链接器错误。

关于c++ - g++ 编译器如何包含 boost::regex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24084470/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com