Reputation: 10415
I'm trying to use boost libraries in my C++ application. I'm trying to compile it using g++ with different options.e.g g++ -I /usr/include/boost/filesystem/ -o test.out test.cpp
however it always prompt error: 'boost' has not been declared
.
And here is my code:
#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;
}
I will be glad if you help me to fix this.
P.S. I'm compiling my application in Centos 4.7 and It contains Boost version 1.32 according to /usr/include/boost/version.hpp
Update:
I also commented boost instruction, but there is some problem with includes: boost/filesystem.hpp: No such file or directory
.
Upvotes: 1
Views: 16266
Reputation: 28854
It sounds like you have not yet installed the boost header files that you need for includes. Since you are on CentOS, you need to:
yum install boost-devel
That will place the header file you want in:
/usr/include/boost/filesystem/path.hpp
Since you are using boost::filesystem::path
, you should change your #include <boost/filesystem.hpp>
to #include <boost/filesystem/path.hpp>
. Since -I /usr/include
is passed to gcc by default, you do not need the -I /usr/include/boost/filesystem
, unless you changed the include to path.hpp
. However, this would be dangerous because another library may have the same header file name and then you may include the wrong header.
Upvotes: 1
Reputation: 10415
Accodring to header files in my Centos Linux, I changed
#include <boost/filesystem.hpp>
to
#include <boost/filesystem/path.hpp>
And also compiled my program with special link options:
g++ test.cpp -o test.out -lboost_filesystem
Upvotes: 1
Reputation: 9
You can try:
g++ -std=c++11 -Os -Wall -pedantic test.cpp -lboost_system -lboost_filesystem -o test
I had the same problem
Let me know if is works
best regards,
Upvotes: 0