I had spent some time trying to get simple boost filesystem operations working, and managed successfully by changing the project settings in XCode. For reference, here is my code that uses boost::filesystem:
namespace bfs = boost::filesystem;
std::cerr << "Before bfs calls" << std::endl;
bfs::path levelDir("data/levels/");
std::cerr << "path object created" << std::endl;
try
{
if (bfs::exists(levelDir) && bfs::is_directory(levelDir))
{
std::cerr << "Directory exists according to bfs" << std::endl;
bfs::directory_iterator endIter;
std::vector<bfs::path> paths;
for (bfs::directory_iterator it = bfs::directory_iterator(levelDir); it != endIter; ++it)
{
if (bfs::is_regular_file(it->status()))
{
paths.push_back(it->path());
}
}
}
}
catch (...)
{
// Handle exception.
}
std::cerr << "After bfs calls" << std::endl;
A problem I had when debugging, was that attempting to step through the code line by line would behave very strangely. Before I got to any boost::filesystem functions/objects the program would continue running, completely skipping over any boost::filesystem code. Additionally the output for the above would be:
Before bfs calls
After bfs calls
During my investigation, I found that the solution was to change the C++ Language Dialect
setting to C++11
and the C++ Standard Library
to libc++
, both in XCode project settings under the Apple LLVM 6.0 Language C++
section. I assume this has to do with matching the settings that boost filesystem was built under.
My program built normally with no errors, and ran fine except whenever I needed to read files in a directory on the filesystem.
So on to my actual question: Since this has to do with a mismatch in compiler settings, why wasn't there a compile/linker error and is there anything I can change in XCode settings to alert me when this is the case? Since the regression happened when I upgraded boost via Homebrew, is there a way to detect the settings used to build libraries? I am also concerned that an update to XCode and its compiler may cause a similar problem.
I am running boost 1.56.0 installed via Homebrew, and XCode 6.0.1.