错误boost::文件系统没有名为string()的成员

error boost::filesystem has no member named string()

本文关键字:string 成员 boost 文件系统 错误      更新时间:2023-10-16

我正试图在我的机器(Ubuntu 12.04 LTS)和集群系统的节点(CentOS)上为一个使用boost的项目构建一个可执行文件。我设法在两台机器上都安装了来自源代码的boost。当我运行make命令时,我可以在我的机器上获得我的项目的可执行文件,但在节点上不能获得。在集群节点上,它说:

source/MainCompressor.cpp: In member function ‘void MainCompressor::compress(std::__cxx11::string, std::__cxx11::string)’:
source/MainCompressor.cpp:76:80: error: ‘boost::filesystem::basic_path<std::__cxx11::basic_string<char>, boost::filesystem::path_traits>::string_type {aka class std::__cxx11::basic_string<char>}’ has no member named ‘string’
         boost::filesystem::copy_file(reference, outpath + reference.filename().string());
                                                                                ^
source/MainCompressor.cpp:93:49: error: ‘boost::filesystem::basic_path<std::__cxx11::basic_string<char>, boost::filesystem::path_traits>::string_type {aka class std::__cxx11::basic_string<char>}’ has no member named ‘string’
     compList << outpath << reference.filename().string() << endl;
                                                 ^
source/MainCompressor.cpp:99:47: error: ‘boost::filesystem::basic_path<std::__cxx11::basic_string<char>, boost::filesystem::path_traits>::string_type {aka class std::__cxx11::basic_string<char>}’ has no member named ‘string’
         string filename = filepath.filename().string();
                                               ^
source/MainCompressor.cpp: In member function ‘void MainCompressor::decompress(std::__cxx11::string, std::__cxx11::string)’:
source/MainCompressor.cpp:171:47: error: ‘boost::filesystem::basic_path<std::__cxx11::basic_string<char>, boost::filesystem::path_traits>::string_type {aka class std::__cxx11::basic_string<char>}’ has no member named ‘string’
         string filename = filepath.filename().string();

我在两台机器上都安装了相同版本的boost(1.55和1.59)。我不知道为什么我的机器上没有出现错误,但节点上出现了错误。在这方面的任何帮助都将不胜感激。

编辑1:以下是我的路径变量设置:

PATH=/home/head/cmp/soft/sft/boost_1_59_0:/home/head/cmp/soft/sft/boost_1_55_0/bin:/home/head/cmp/soft/sft/gcc/bin:$PATH

对我来说,节点上似乎安装了旧版本的boost。旧版本的boost::filesystem::path没有string成员函数。检查include路径,编译器会从某个地方得到错误的头。您可以在gcc命令行中添加一些额外的参数,以查看实际使用了哪些包含文件。请参阅:/在g++中显示包含等效选项