fledder
August 26th, 2007, 11:17 AM
hi,
I am new to C++ programming but not new to Ubuntu. I am using Eclipse on Ubuntu 6.10. I want to make use of the Boost C++ libraries, particularly the file system library. I have successfully installed both the general and the specific file system libraries. I can also successfully include them in my program. So far, so good.
Problems arrive however when I want to compile a Boost sample program, as taken directly from the Boost site. Here's the code:
// simple_ls program -------------------------------------------------------//
// Copyright Jeff Garland and Beman Dawes, 2002
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/filesystem for documentation.
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/progress.hpp"
#include <iostream>
namespace fs = boost::filesystem;
int main( int argc, char* argv[] )
{
boost::progress_timer t( std::clog );
fs::path full_path( fs::initial_path<fs::path>() );
if ( argc > 1 )
full_path = fs::system_complete( fs::path( argv[1], fs::native ) );
else
std::cout << "\nusage: simple_ls [path]" << std::endl;
unsigned long file_count = 0;
unsigned long dir_count = 0;
unsigned long other_count = 0;
unsigned long err_count = 0;
if ( !fs::exists( full_path ) )
{
std::cout << "\nNot found: " << full_path.native_file_string() << std::endl;
return 1;
}
if ( fs::is_directory( full_path ) )
{
std::cout << "\nIn directory: "
<< full_path.native_directory_string() << "\n\n";
fs::directory_iterator end_iter;
for ( fs::directory_iterator dir_itr( full_path );
dir_itr != end_iter;
++dir_itr )
{
try
{
if ( fs::is_directory( dir_itr->status() ) )
{
++dir_count;
std::cout << dir_itr->path().leaf() << " [directory]\n";
}
else if ( fs::is_regular( dir_itr->status() ) )
{
++file_count;
std::cout << dir_itr->path().leaf() << "\n";
}
else
{
++other_count;
std::cout << dir_itr->path().leaf() << " [other]\n";
}
}
catch ( const std::exception & ex )
{
++err_count;
std::cout << dir_itr->path().leaf() << " " << ex.what() << std::endl;
}
}
std::cout << "\n" << file_count << " files\n"
<< dir_count << " directories\n"
<< other_count << " others\n"
<< err_count << " errors\n";
}
else // must be a file
{
std::cout << "\nFound: " << full_path.native_file_string() << "\n";
}
return 0;
}
Trying to compile this in Eclipse gives me the following compilation errors:
**** Build of configuration Debug for project ListFiles_Boost ****
make -k all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
../main.cpp: In function ‘int main(int, char**)’:
../main.cpp:21: error: expected primary-expression before ‘>’ token
../main.cpp:21: error: expected primary-expression before ‘)’ token
../main.cpp:50: error: ‘class boost::filesystem::path’ has no member named ‘status’
../main.cpp:53: error: invalid use of ‘class boost::filesystem::path’
../main.cpp:55: error: ‘is_regular’ is not a member of ‘fs’
../main.cpp:55: error: ‘class boost::filesystem::path’ has no member named ‘status’
../main.cpp:58: error: invalid use of ‘class boost::filesystem::path’
../main.cpp:63: error: invalid use of ‘class boost::filesystem::path’
../main.cpp:70: error: invalid use of ‘class boost::filesystem::path’
make: *** [main.o] Error 1
make: Target `all' not remade because of errors.
Build complete for project ListFiles_Boost
I would expect that a code sample from the people documenting the library would work, so it must be me doing something wrong? I have not set any specific project properties in Eclipse, and am not sure if I should? Any other clues why I am getting these errors?
Not very constructive to say, but it does bother me that doing something as simple as looping through a directory is so much trouble in C++.
Thanks so much in advance,
Ferdy
I am new to C++ programming but not new to Ubuntu. I am using Eclipse on Ubuntu 6.10. I want to make use of the Boost C++ libraries, particularly the file system library. I have successfully installed both the general and the specific file system libraries. I can also successfully include them in my program. So far, so good.
Problems arrive however when I want to compile a Boost sample program, as taken directly from the Boost site. Here's the code:
// simple_ls program -------------------------------------------------------//
// Copyright Jeff Garland and Beman Dawes, 2002
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/filesystem for documentation.
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/progress.hpp"
#include <iostream>
namespace fs = boost::filesystem;
int main( int argc, char* argv[] )
{
boost::progress_timer t( std::clog );
fs::path full_path( fs::initial_path<fs::path>() );
if ( argc > 1 )
full_path = fs::system_complete( fs::path( argv[1], fs::native ) );
else
std::cout << "\nusage: simple_ls [path]" << std::endl;
unsigned long file_count = 0;
unsigned long dir_count = 0;
unsigned long other_count = 0;
unsigned long err_count = 0;
if ( !fs::exists( full_path ) )
{
std::cout << "\nNot found: " << full_path.native_file_string() << std::endl;
return 1;
}
if ( fs::is_directory( full_path ) )
{
std::cout << "\nIn directory: "
<< full_path.native_directory_string() << "\n\n";
fs::directory_iterator end_iter;
for ( fs::directory_iterator dir_itr( full_path );
dir_itr != end_iter;
++dir_itr )
{
try
{
if ( fs::is_directory( dir_itr->status() ) )
{
++dir_count;
std::cout << dir_itr->path().leaf() << " [directory]\n";
}
else if ( fs::is_regular( dir_itr->status() ) )
{
++file_count;
std::cout << dir_itr->path().leaf() << "\n";
}
else
{
++other_count;
std::cout << dir_itr->path().leaf() << " [other]\n";
}
}
catch ( const std::exception & ex )
{
++err_count;
std::cout << dir_itr->path().leaf() << " " << ex.what() << std::endl;
}
}
std::cout << "\n" << file_count << " files\n"
<< dir_count << " directories\n"
<< other_count << " others\n"
<< err_count << " errors\n";
}
else // must be a file
{
std::cout << "\nFound: " << full_path.native_file_string() << "\n";
}
return 0;
}
Trying to compile this in Eclipse gives me the following compilation errors:
**** Build of configuration Debug for project ListFiles_Boost ****
make -k all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
../main.cpp: In function ‘int main(int, char**)’:
../main.cpp:21: error: expected primary-expression before ‘>’ token
../main.cpp:21: error: expected primary-expression before ‘)’ token
../main.cpp:50: error: ‘class boost::filesystem::path’ has no member named ‘status’
../main.cpp:53: error: invalid use of ‘class boost::filesystem::path’
../main.cpp:55: error: ‘is_regular’ is not a member of ‘fs’
../main.cpp:55: error: ‘class boost::filesystem::path’ has no member named ‘status’
../main.cpp:58: error: invalid use of ‘class boost::filesystem::path’
../main.cpp:63: error: invalid use of ‘class boost::filesystem::path’
../main.cpp:70: error: invalid use of ‘class boost::filesystem::path’
make: *** [main.o] Error 1
make: Target `all' not remade because of errors.
Build complete for project ListFiles_Boost
I would expect that a code sample from the people documenting the library would work, so it must be me doing something wrong? I have not set any specific project properties in Eclipse, and am not sure if I should? Any other clues why I am getting these errors?
Not very constructive to say, but it does bother me that doing something as simple as looping through a directory is so much trouble in C++.
Thanks so much in advance,
Ferdy