c++ - cmake, boost::filesystem linking error (undefined directory_iterator.operator!=) -


i'm using cmake (2.8.3), boost::filesystem(1.42.0) in ubuntu 10.10. code compiles ok keep getting following error when linking:

cmakefiles/sample.dir/sample.cpp.o: in function `main': sample.cpp:(.text+0x1af8d): undefined reference `int operator!=<boost::filesystem::basic_directory_iterator<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> > >(boost::filesystem::basic_directory_iterator<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> > const&, boost::filesystem::basic_directory_iterator<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> > const&)' collect2: ld returned 1 exit status 

the code in question following:

#include <boost/filesystem.hpp> #include <boost/algorithm/string.hpp>  int main() {   string folder;   string extension;   fs::directory_iterator end;    folder    = ".";   extension = ".zip";    (fs::directory_iterator i(folder); != end; ++i)   { if (fs::is_regular_file(i->status()))     {       if (boost::algorithm::ends_with(i->leaf(), extension))       {         cout << i->leaf() << " has extension .zip" << endl;       }     }   } } 

in cmakelists.txt file, have:

find_package(boost 1.4.0 components filesystem required) include_directories(${boost_include_dirs})  target_link_libraries(executable     ${boost_libraries}) 

but i've tried with:

set(boost_use_static_libs        on) set(boost_use_multithreaded      on) set(boost_use_static_runtime    off) find_package(boost 1.4.0 components filesystem required) include_directories(${boost_include_dirs})  target_link_libraries(executable     ${boost_filesystem_library}) 

and many other combinations of above.

the linker complaining != operator directory_iterator type. if contents of header in /usr/include/boost/filesystem/path.cpp can see operator defined there. ideas why happening?

i'd appreciate help.

after adding missing include files:

#include <string> #include <iostream> 

and namespaces (std), , defining macro "fs" shortcut of code:

#define fs boost::filesystem 

then tried first cmakelists.txt approach mentioned, , worked... have same system you.

what recommend using message in cmake inspect these $boost_* variables , debug bit compilation system it...


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -