Compile error (BEI 2) 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.
Operating system: Ubuntu 10.04 LTS Lucid Lynx
IDE: gedit
#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'; } //---------------------------------------------------------------------------
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/include -I/usr/include/boost -L/usr/local/lib -lboost_filesystem
Or using the more elaborate form:
i586-mingw32msvc-g++ -V 4.4.2 -x c++ -o MyWin.exe main.cpp -I/usr/include -I/usr/include/boost -L/usr/local/lib -lboost_filesystem
This resulted in the following screen output:
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
Zooming in on the first error:
Take a look at /usr/include/stdio.h line 430:
extern int __REDIRECT (sscanf, (__const char *__restrict __s, __const char *__restrict __format, ...), __isoc99_sscanf) __THROW;
It seems as if a re-throw (that is, a throw without arguments) is unsupported by i586-mingw32msvc-g++. Is it true that stdio.h is a C library file, as stated in its licence?
I tried to reinstall mingw:
This did not solve the error.
Including the mingw32 header files, solves this problem:
i586-mingw32msvc-g++ -o MyWin.exe main.cpp -I/usr/i586-mingw32msvc/include -I/usr/include/boost -L/usr/local/lib -lboost_filesystem
But this takes one to the next problem: boost/filesystem.hpp: No such file or directory.