This is my first question on SO. Here goes:
I'm trying to use the boost library - specifically the filesystem part - in a C++ project in Xcode 8.
Apple Mach-O Linker (ld) Error Group
"boost::filesystem::detail::dir_itr_close(void*&, void*&)", referenced from:
"boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)", referenced from:
"boost::filesystem::detail::directory_iterator_increment(boost::filesystem::directory_iterator&, boost::system::error_code*)", referenced from:
"boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
"boost::system::system_category()", referenced from:
"boost::system::generic_category()", referenced from:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
int main(int argc, char *argv[])
{
std::string dir_path = "foo/bar";
if ( !boost::filesystem::exists( dir_path ) ) return false;
boost::filesystem::directory_iterator end_itr; // default construction
yields past-the-end
for ( boost::filesystem::directory_iterator itr( dir_path );
itr != end_itr;
++itr )
{
std::cout << itr->path();
}
return 0;
}
brew install boost --build-from-source --c++11
. I read somewhere that passing this --c++11
flag should fix it, and the --build-from-source
is required so that the flag is actually passed to the b2 compiler. #include <boost/filesystem.hpp>
in my project. /usr/local/include
to my Header Search Paths under Build Settings . (Also tried adding /usr/local/include/boost
and /usr/local/include/boost/system
there, to no avail. Also, setting the recursive option on any of my Header Search Paths makes Xcode freak out). /usr/local/lib
to my Library Search Paths . -lboost_system -lboost_filesystem
to my Other Linker Flags . (Also tried adding -lboost_system-mt
, which I saw other answers suggesting). #include <boost/filesystem.hpp>
causes the last 2 linker errors (about the boost::system::system_category()
and generic_category()
) to occur. However, with #include <boost/regex.hpp>
, the program will build successfully. argvs[]
to my program, but I could be dealing with tens of thousands of files per folder and I suspect that might get ugly. I am very new to C++ and almost as new to Xcode. I've spent about 8h trying to get this to work.
Thanks a lot for the help!
I got the same error and this is how I fixed it.
Build Settings > Header Search Paths > (Add) /usr/local/include
Build Settings > Library Search Paths > (Add) /usr/local/lib
Build Settings > Other Linker Flags > (Add) -l boost_system -l boost_filesystem
I hope this helps someone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.