I have been searching high and low to get this question answered, and I can't seem to debug the problem out!
So, this is what I have.
I have installed boost via homebrew (Mac OSX Mavericks) version 1.55.0.
Other boost libraries work fine, but boost::filesystem
doesn't seem to be able to interact with the actual filesystem.
This is how I am linking it (using QT)
macx: LIBS += -L$$PWD/../../../../../usr/local/Cellar/boost/1.55.0_1/lib/ -lboost_system-mt
macx: LIBS += -L$$PWD/../../../../../usr/local/Cellar/boost/1.55.0_1/lib/ -lboost_filesystem-mt
INCLUDEPATH += $$PWD/../../../../../usr/local/Cellar/boost/1.55.0_1/include
DEPENDPATH += $$PWD/../../../../../usr/local/Cellar/boost/1.55.0_1/include
macx: PRE_TARGETDEPS += $$PWD/../../../../../usr/local/Cellar/boost/1.55.0_1/lib/libboost_filesystem.a
macx: PRE_TARGETDEPS += $$PWD/../../../../../usr/local/Cellar/boost/1.55.0_1/lib/libboost_system.a
Please note that this was auto-generated by qt creator via the Add Library interface.
Here is the code I am running that never works. (meaning isDir is always false
)
namespace fs = boost::filesystem;
boost::system::error_code c;
fs::path path("/path/to/some/dir"); // Have tried '.' '/' './' '/usr' Everything!
bool isDir = boost::filesystem::is_directory(path, c);
if(!isDir) {
std::cout << "Error Response: " << c << std::endl;
ui->directoryEdit->setStyleSheet("background-color: red;");
}
else {
std::cout << "Is a directory!" << std::endl;
}
The result of the output is always system: 2
from boost::system::error_code
Addition Findings:
- When attempting to print the path, the application crashes
- I have re compiled boost with c++11 instead of the standard but nothing changed.
I am sure I am missing something blatantly obvious, but I admit I need help.
EDIT:
So I have isolated it into a single main.cpp file:
#include <boost/filesystem.hpp>
#include <boost/system/error_code.hpp>
#include <iostream>
#include <string>
int main(int argc, char *argv[]) {
namespace fs = boost::filesystem;
boost::system::error_code c;
fs::path path("."); // Have tried '.' '/' './' '/usr' Everything!
bool isDir = boost::filesystem::is_directory(path, c);
if(!isDir) {
std::cout << "Error Response: " << c << std::endl;
}
else {
std::cout << "Is a directory!" << std::endl;
}
return 0;
}
And I compile / run with
g++ test_boost.cpp -o main.out -lboost_system -lboost_filesystem
./main.out
And the generated response is
Error Response: system:2
Very frustrating. Going to try with an older version
EDIT 2:
Per request in comments here is /usr/local/Cellar/boost/1.55.0_1/INSTALL_RECEIPT.json
{"compiler":"clang","HEAD":"4bf4ee77fa858bb5e56406504cf86564bd5ece3d","built_as_bottle":true,"stdlib":"libcxx","tapped_from":"Homebrew/homebrew","unused_options":["--with-mpi","--c++11","--with-icu","--without-static","--with-python","--universal","--without-single"],"poured_from_bottle":true,"used_options":[],"time":1399557362}
EDIT 3:
g++ version:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix
c++ version:
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix