I'm running into problems with Boost's filesystem lib (1.60.0). After spending a couple of hours tearing through my code assuming it was something I was doing wrong, I tried running Boost's own filesystem examples and had the same problem. All of this works fine when compiling with gcc on OSX, but not on Ubuntu 14.04.
I tried defining BOOST_NO_CXX11_SCOPED_ENUMS both in the code, and also tried it as an argument when running g++. I also tried removing -std=c++11 (I saw in one case, that seemed to help someone who ran into this problem). Regardless, it always fails on Ubuntu. The Boost example I'm using is this:
// tut1
#include <iostream>
#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: tut1 path\n";
return 1;
}
std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
return 0;
}
And the result of trying to compile that looks like this:
vagrant@testing:~/boost_fs_test$ g++ -I/boost/1_60_0/include -L/boost/1_60_0/lib -lboost_system -lboost_filesystem test2.cpp -o test2
/tmp/cck0AVVX.o: In function `__static_initialization_and_destruction_0(int, int)':
test2.cpp:(.text+0x105): undefined reference to `boost::system::generic_category()'
test2.cpp:(.text+0x111): undefined reference to `boost::system::generic_category()'
test2.cpp:(.text+0x11d): undefined reference to `boost::system::system_category()'
/tmp/cck0AVVX.o: In function `boost::filesystem::file_size(boost::filesystem::path const&)':
test2.cpp:(.text._ZN5boost10filesystem9file_sizeERKNS0_4pathE[_ZN5boost10filesystem9file_sizeERKNS0_4pathE]+0x19): undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)'
collect2: error: ld returned 1 exit status
vagrant@testing:~/boost_fs_test$ g++ -std=c++11 -I/boost/1_60_0/include -L/boost/1_60_0/lib -lboost_system -lboost_filesystem test2.cpp -o test2
/tmp/cceGCjpc.o: In function `__static_initialization_and_destruction_0(int, int)':
test2.cpp:(.text+0x105): undefined reference to `boost::system::generic_category()'
test2.cpp:(.text+0x111): undefined reference to `boost::system::generic_category()'
test2.cpp:(.text+0x11d): undefined reference to `boost::system::system_category()'
/tmp/cceGCjpc.o: In function `boost::filesystem::file_size(boost::filesystem::path const&)':
test2.cpp:(.text._ZN5boost10filesystem9file_sizeERKNS0_4pathE[_ZN5boost10filesystem9file_sizeERKNS0_4pathE]+0x19): undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)'
collect2: error: ld returned 1 exit status
I triple-checked how I installed Boost and everything looks correct. The libs are definitely in the right place:
-rw-rw-r-- 1 vagrant vagrant 237886 Jan 8 08:41 libboost_filesystem.a
lrwxrwxrwx 1 vagrant vagrant 29 Jan 8 08:40 libboost_filesystem.so -> libboost_filesystem.so.1.60.0
-rwxrwxr-x 1 vagrant vagrant 126186 Jan 8 08:40 libboost_filesystem.so.1.60.0
-rw-rw-r-- 1 vagrant vagrant 49226 Jan 8 08:41 libboost_system.a
lrwxrwxrwx 1 vagrant vagrant 25 Jan 8 08:40 libboost_system.so -> libboost_system.so.1.60.0
-rwxrwxr-x 1 vagrant vagrant 20469 Jan 8 08:40 libboost_system.so.1.60.0
The same exact code compiles fine on OSX, though:
jack-burton:boost_fs fny$ g++ -std=c++11 -I/usr/local/Cellar/boost/1.60.0_1/include -L/usr/local/Cellar/boost/1.60.0_1/lib -lboost_system -lboost_filesystem test2.cpp -o test2
jack-burton:boost_fs fny$ ls
test2 test2.cpp
jack-burton:boost_fs fny$ ./test2 test2.cpp
test2.cpp 321
I'm not really sure what I'm missing here. For the sake of curiosity, I tried using apt to install Boost (which installed 1.54) and had the same problem.