0

I am new to boost. I am trying to follow a tutorial to learn how to obtain all the files in a directory. I have finally gotten it to find the header file but I cannot get this simple tutorial script to compile. I have read over similar errors but none of them are over the directory_iterator that I am trying to use.

I am using a TACC super computer. I module load boost/1.68. I even copied it into an include directory in my directory. I need my code to compile with the iclc compiler. I cannot use g++ or clang. This is a requirement for my class project that I am trying to use the filesystem for.

I am unable to just use the regular #include. the icpc compiler doesn't find the header file and I am unsure about how to go about finding it.

This is how I compile my code.

icpc -I ./include/boost scratch_fs.cpp 

Here is my code

#include <string>
#include <iostream>
#include "boost/filesystem.hpp"
#include <fstream>


using namespace boost::filesystem;

int main()
{
    std::string path = "/path/to/directory";
    for (auto & entry : directory_iterator(path))
        std::cout << entry.path() << std::endl;
}

Here is the error message I get

/tmp/icpcMNLwud.o: In function `main':
scratch_fs.cpp:(.text+0x1b4): undefined reference to `boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
scratch_fs.cpp:(.text+0x3cb): undefined reference to `boost::filesystem::detail::directory_iterator_increment(boost::filesystem::directory_iterator&, boost::system::error_code*)'
/tmp/icpcMNLwud.o: In function `void boost::checked_delete<boost::filesystem::detail::dir_itr_imp>(boost::filesystem::detail::dir_itr_imp*)':
scratch_fs.cpp:(.text._ZN5boost14checked_deleteINS_10filesystem6detail11dir_itr_impEEEvPT_[_ZN5boost14checked_deleteINS_10filesystem6detail11dir_itr_impEEEvPT_]+0x19): undefined reference to `boost::filesystem::detail::dir_itr_close(void*&, void*&)'
/tmp/icpcMNLwud.o: In function `boost::detail::sp_counted_impl_p<boost::filesystem::detail::dir_itr_imp>::dispose()':
scratch_fs.cpp:(.text._ZN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEE7disposeEv[_ZN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEE7disposeEv]+0x17): undefined reference to `boost::filesystem::detail::dir_itr_close(void*&, void*&)'
/tmp/icpcMNLwud.o: In function `boost::system::error_category::std_category::equivalent(std::error_code const&, int) const':
scratch_fs.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0x34): undefined reference to `boost::system::detail::generic_category_instance'
scratch_fs.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0x9e): undefined reference to `boost::system::detail::generic_category_instance'
scratch_fs.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xea): undefined reference to `boost::system::detail::generic_category_instance'
/tmp/icpcMNLwud.o: In function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
scratch_fs.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0x2b): undefined reference to `boost::system::detail::generic_category_instance'
scratch_fs.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xa8): undefined reference to `boost::system::detail::generic_category_instance'

Any help is much appreciated!

Danny Diaz
  • 375
  • 1
  • 4
  • 12
  • I don't know that compiler but you probably need to add linking the boost filesystem library (and maybe some other boost library too). Try adding `-lboost_filesystem -lboost_system` when compiling. – Ted Lyngmo May 14 '19 at 21:06
  • It just returned cannot find -lboost_filesystem. Same for -lboost_system. I thought linking was what my -I flag was doing? – Danny Diaz May 14 '19 at 21:15
  • I just read a little about the compiler and I'm not sure how to supply libraries to it. Perhaps you should skip `-l` and just add `libboost_filesystem.a libboost_system.a` when compiling. That is, if you have static boost libraries installed. Search for `libboost_filesystem.*` on your machine and see if you find `.a` or `.so` files. The `-I` that you added is just pointing out where to search for header files. – Ted Lyngmo May 14 '19 at 21:19
  • I started reading about -lboost_filesystem -lboost_system and ended up finding a link that showed me how to add the library https://stackoverflow.com/questions/17206298/how-to-link-boost-libraries-properly-in-linux. I used this along with a TACC specific environment variable of where the boost library was and it compiled! thank you! – Danny Diaz May 14 '19 at 22:28
  • Great! Glad it lead you in the right direction! – Ted Lyngmo May 15 '19 at 04:23
  • You have to link with -lboost_filesystem -lboost_system. Boost filesystem is not a header-only library; rather, it depends on compiled components. – Mausam Sinha Aug 09 '20 at 15:47

0 Answers0