Note that there are some explanatory texts on larger screens.

plurals
  1. POcmake, boost::filesystem linking error (undefined directory_iterator.operator!=)
    text
    copied!<p>I'm using CMake (2.8.3), Boost::filesystem(1.42.0) in Ubuntu 10.10. The code compiles OK but I keep getting the following error when linking:</p> <pre><code>CMakeFiles/sample.dir/sample.cpp.o: In function `main': sample.cpp:(.text+0x1af8d): undefined reference to `int operator!=&lt;boost::filesystem::basic_directory_iterator&lt;boost::filesystem::basic_path&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, boost::filesystem::path_traits&gt; &gt; &gt;(boost::filesystem::basic_directory_iterator&lt;boost::filesystem::basic_path&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, boost::filesystem::path_traits&gt; &gt; const&amp;, boost::filesystem::basic_directory_iterator&lt;boost::filesystem::basic_path&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, boost::filesystem::path_traits&gt; &gt; const&amp;)' collect2: ld returned 1 exit status </code></pre> <p>The code in question is the following:</p> <pre><code>#include &lt;boost/filesystem.hpp&gt; #include &lt;boost/algorithm/string.hpp&gt; int main() { string folder; string extension; fs::directory_iterator end; folder = "."; extension = ".zip"; for (fs::directory_iterator i(folder); i != end; ++i) { if (fs::is_regular_file(i-&gt;status())) { if (boost::algorithm::ends_with(i-&gt;leaf(), extension)) { cout &lt;&lt; i-&gt;leaf() &lt;&lt; " has extension .zip" &lt;&lt; endl; } } } } </code></pre> <p>in my <code>CMakeLists.txt</code> file, I have:</p> <pre><code>find_package(Boost 1.4.0 COMPONENTS filesystem REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) target_link_libraries(executable ${Boost_LIBRARIES}) </code></pre> <p>but I've also tried with:</p> <pre><code>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}) </code></pre> <p>and many other combinations of the above.</p> <p>The linker is complaining about the <code>!=</code> operator for the <code>directory_iterator</code> type. If I look to the contents of the header in <code>/usr/include/boost/filesystem/path.cpp</code> I can see that the operator is defined there. Any ideas why this is happening?</p> <p>I'd really appreciate your help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload