我有以下程序,它递归遍历目录中的所有文件 - >
#include "boost/filesystem.hpp"
#include "boost/regex.hpp"
#include "string"
#include <iostream>
using namespace boost;
using namespace std;
int main()
{
filesystem::path current_dir("."); //
boost::regex pattern("a.*"); // list all files starting with a
for (filesystem::recursive_directory_iterator iter(current_dir), end;
iter != end;
++iter)
{
std::string name = iter->path().filename().string();
if (regex_match(name, pattern))
std::cout << iter->path() << "\n";
}
}
我使用命令编译此程序:
g++ directory_iterate.cpp -lboost_filesystem -lboost_regex -lboost_system
我收到以下错误:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../libboost_regex.so: undefined reference to `std::__detail::_List_node_base::_M_unhook()@GLIBCXX_3.4.15'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../libboost_regex.so: undefined reference to `std::overflow_error::~overflow_error()@GLIBCXX_3.4.15'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../libboost_regex.so: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)@GLIBCXX_3.4.15'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../libboost_regex.so: undefined reference to `std::invalid_argument::~invalid_argument()@GLIBCXX_3.4.15'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../libboost_filesystem.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../libboost_regex.so: undefined reference to `std::__detail::_List_node_base::_M_transfer(std::__detail::_List_node_base*, std::__detail::_List_node_base*)@GLIBCXX_3.4.15'