错误:"提升"尚未声明
error: `boost' has not been declared
我正试图在C++应用程序中使用boost库。我试着用g++和不同的选项编译它。例如g++ -I /usr/include/boost/filesystem/ -o test.out test.cpp
,但它总是提示error: 'boost' has not been declared
。
这是我的代码:
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
using namespace std;
int main (){
string line;
string fileName = "Read.txt";
ifstream file;
string str;
file.open(fileName.c_str());
cout << "Hello, world!n";
vector<string> fileLines;
fileLines.clear();
while (getline(file, str))
{
fileLines.push_back(line);
}
cout << "Total Line count:"<<fileLines.size()<<endl;
fileLines.clear();
cout << "Total Line count:"<<fileLines.size()<<endl;
boost::filesystem::path p("/tmp/foo.txt");
return 0;
}
如果你帮我解决这个问题,我会很高兴的。
附言:我正在Centos 4.7中编译我的应用程序,它包含根据/usr/include/boost/version.hpp
的Boost 1.32版本
更新:
我也评论了boost指令,但include:boost/filesystem.hpp: No such file or directory
有一些问题。
听起来您还没有安装include所需的boost头文件。由于您在CentOS上,您需要:
yum install boost-devel
这将把你想要的头文件放在:
/usr/include/boost/filesystem/path.hpp
由于您使用的是boost::filesystem::path
,因此应将#include <boost/filesystem.hpp>
更改为#include <boost/filesystem/path.hpp>
。由于默认情况下-I /usr/include
传递给gcc,因此不需要-I /usr/include/boost/filesystem
,除非将include更改为path.hpp
。然而,这将是危险的,因为另一个库可能具有相同的头文件名,然后您可能包含错误的头。
您可以尝试:g++ -std=c++11 -Os -Wall -pedantic test.cpp -lboost_system -lboost_filesystem -o test
我遇到了同样的问题
让我知道它是否有效
问候,
根据Centos Linux中的头文件,我更改了
#include <boost/filesystem.hpp>
至
#include <boost/filesystem/path.hpp>
还编译了我的程序与特殊的链接选项:
g++ test.cpp -o test.out -lboost_filesystem
- #ifdef和未声明的标识符
- 未声明的标识符编译暗黑破坏神 2 程序"muleview"
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- Google protobuf 时间戳未声明标识符,在 Windows 上具有C++
- 在气泡排序程序中未声明错误功能
- 我在范围内未声明的错误类有问题
- 使用未声明的标识符"sqrt"?
- 我包含了<winuser.h>,但编译器在MonitorFromWindow上抛出"未声明"
- 对类 (C++) 中的私有变量使用未声明的标识符
- 我的代码中有错误,未声明的标识符
- 未定义的标识符/未声明
- 错误:在 C++ 'std'使用未声明的标识符
- 在编译器之前检测未声明的标识符
- 使用未声明的标识符'temp'
- 使用未声明的标识符"yylex"和"yyin"?
- 使用"class"关键字,后跟未声明的标识符
- 未声明的标识符错误,但变量定义正确 (?)
- C2065 'cout':未声明的标识符
- 在此范围内未声明错误"Clreol"
- 提升directory_iterator:未声明'begin'和'end'