Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) boost/filesystem.hpp: No such file or directory

 

Compile error (BEI 3) I encountered while busy solving How to cross-compile a Qt Creator project from Ubuntu to a windows executable: example 3: console application with a Boost library.

 

 

 

 

 

 

 

System specifics

 

Operating system: Ubuntu 10.04 LTS Lucid Lynx

IDE: gedit

 

 

 

 

 

Source code: main.cpp

 

#include <iostream>
#include <string>
#include <vector>
//---------------------------------------------------------------------------
#include <boost/filesystem.hpp>
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppGetFilesInFolder.htm
const std::vector<std::string> GetFilesInFolder(const std::string& folder)
{
  std::vector<std::string> v;

  const boost::filesystem::path my_folder
    = boost::filesystem::system_complete(
        boost::filesystem::path(folder));

  if (!boost::filesystem::is_directory(my_folder)) return v;

  const boost::filesystem::directory_iterator j;
  for ( boost::filesystem::directory_iterator i(my_folder);
        i != j;
        ++i)
  {
    if ( boost::filesystem::is_regular_file( i->status() ) )
    {
      const std::string filename = i->path().filename();
      //const std::string full_filename = folder + "/" + filename;
      v.push_back(filename);
    }
  }
  return v;
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppGetPath.htm
const std::string GetPath(const std::string& filename)
{
  return boost::filesystem::path(filename).parent_path().string();
}
//---------------------------------------------------------------------------
int main(int, char* argv[])
{
  const std::vector<std::string> v = GetFilesInFolder(GetPath(argv[0]));
  std::copy(v.begin(),v.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
  std::cout << "Number of files: " << v.size() << '\n';
}
//---------------------------------------------------------------------------

 

 

 

 

 

Process

 

Because I was trying to solve the Qt FAQ How to cross-compile a Qt Creator project from Ubuntu to a windows executable?, I compiled the code as follows:

 

i586-mingw32msvc-g++ -o MyWin.exe main.cpp -I/usr/i586-mingw32msvc/include -L/usr/local/lib -lboost_filesystem

 

This resulted in the following screen output:

 

main.cpp:9:32: error: boost/filesystem.hpp: No such file or directory
main.cpp: In function 'const std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > GetFilesInFolder(const std::string&)':
main.cpp:16: error: 'boost' has not been declared
main.cpp:16: error: expected initializer before 'my_folder'
main.cpp:20: error: 'boost' has not been declared
main.cpp:20: error: 'my_folder' was not declared in this scope
main.cpp:22: error: 'boost' has not been declared
main.cpp:22: error: expected initializer before 'j'
main.cpp:23: error: 'boost' has not been declared
main.cpp:23: error: expected `;' before 'i'
main.cpp:24: error: 'i' was not declared in this scope
main.cpp:24: error: 'j' was not declared in this scope
main.cpp:27: error: 'boost' has not been declared
main.cpp: In function 'const std::string GetPath(const std::string&)':
main.cpp:40: error: 'boost' has not been declared
main.cpp: In function 'int main(int, char**)':
main.cpp:46: error: 'ostream_iterator' is not a member of 'std'
main.cpp:46: error: expected primary-expression before '>' token
richel@richel1-desktop:~/qtsdk-2010.04/bin/Projects/Website/CppQtCrosscompileToWindowsExample3$ gedit crosscompile.sh
richel@richel1-desktop:~/qtsdk-2010.04/bin/Projects/Website/CppQtCrosscompileToWindowsExample3$ ./crosscompile.sh
In file included from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cstdio:53,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/i586-mingw32msvc/bits/c++locale.h:49,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/iosfwd:45,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/ios:43,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/ostream:45,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/iostream:45,
                 from main.cpp:5:
/usr/include/stdio.h:430: error: expected initializer before 'throw'
/usr/include/stdio.h:488: error: expected initializer before 'throw'
In file included from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cwchar:55,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/bits/postypes.h:46,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/iosfwd:49,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/ios:43,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/ostream:45,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/iostream:45,
                 from main.cpp:5:
/usr/include/wchar.h:718: error: expected initializer before 'throw'
In file included from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/bits/postypes.h:46,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/iosfwd:49,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/ios:43,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/ostream:45,
                 from /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/iostream:45,
                 from main.cpp:5:
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cwchar:153: error: '::fwide' has not been declared
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cwchar:154: error: '::fwprintf' has not been declared
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cwchar:155: error: '::fwscanf' has not been declared
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cwchar:164: error: '::swprintf' has not been declared
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cwchar:165: error: '::swscanf' has not been declared
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cwchar:167: error: '::vfwprintf' has not been declared
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cwchar:171: error: '::vswprintf' has not been declared
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cwchar:175: error: '::vwprintf' has not been declared
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cwchar:205: error: '::wprintf' has not been declared
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include/c++/cwchar:206: error: '::wscanf' has not been declared
richel@richel1-desktop:~/qtsdk-2010.04/bin/Projects/Website/CppQtCrosscompileToWindowsExample3$ gedit crosscompile.sh
richel@richel1-desktop:~/qtsdk-2010.04/bin/Projects/Website/CppQtCrosscompileToWindowsExample3$ ./crosscompile.sh
main.cpp:9:32: error: boost/filesystem.hpp: No such file or directory
main.cpp: In function 'const std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > GetFilesInFolder(const std::string&)':
main.cpp:16: error: 'boost' has not been declared
main.cpp:16: error: expected initializer before 'my_folder'
main.cpp:20: error: 'boost' has not been declared
main.cpp:20: error: 'my_folder' was not declared in this scope
main.cpp:22: error: 'boost' has not been declared
main.cpp:22: error: expected initializer before 'j'
main.cpp:23: error: 'boost' has not been declared
main.cpp:23: error: expected `;' before 'i'
main.cpp:24: error: 'i' was not declared in this scope
main.cpp:24: error: 'j' was not declared in this scope
main.cpp:27: error: 'boost' has not been declared
main.cpp: In function 'const std::string GetPath(const std::string&)':
main.cpp:40: error: 'boost' has not been declared
main.cpp: In function 'int main(int, char**)':
main.cpp:46: error: 'ostream_iterator' is not a member of 'std'
main.cpp:46: error: expected primary-expression before '>' token

 

When compiling normally, just add /usr/include to the include paths. In this case, one has to copy the Boost source code to /usr/i586-mingw32msvc/include:

 

sudo mkdir /usr/i586-mingw32msvc/include/boost
sudo cp -r /usr/include/boost /usr/i586-mingw32msvc/include

 

This solves this problem, and takes you to the next: cannot find -lboost_filesystem.

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict