添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
闷骚的跑步鞋  ·  mysql ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to make a directory using Boost.Filesystem (the directory can be provided by the user, so it may be a path with nested directories; all, some, or none of the directories in that path may exist to start). When I run the program, a directory is created, but it is not what I asked for; the string containing the path appears to be getting mangled. I never get the same result twice, but the name of the directory always starts with a colon.

A minimal example:

#include <iostream>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
int main(int argc, char* argv[]) {
    fs::path path = "junk/morejunk";
    if (!fs::create_directories(path)) {
        std::cerr << "Failed to create directory " << path << ".\n";
    return(0);

Running that, I get directories such as :@K%C5?, :%C0)%E0?, and :%C0%E9%93?.

I had some trouble getting Boost to link correctly, but the above program compiles and runs now. In case it's necessary, some information:
-- I'm using a Mac (OSX 10.9.4)
-- GCC and Boost both installed with MacPorts (Boost with the +gcc49 option)
-- GCC version 4.9.2_1
-- Boost version 1.57.0_1
-- my Makefile looks like

CC = /opt/local/bin/g++
FLAGS = -I/opt/local/include -L/opt/local/lib -lboost_system-mt -lboost_filesystem-mt
driver : driver.cpp
    $(CC) $(FLAGS) -o driver driver.cpp

Any suggestions welcome; it's been a while since I've used C++ much, and I'm not very experienced with Boost.

Out on a limb, make sure you save your file as ASCII, latin1 or UTF8.

Otherwise you might have undefined behaviour from incompatible library versions.

You could use DYLD_LIBRARY_PATH to get the preferred libraries for boost (the ones which you link against). See also Is it OK to use DYLD_LIBRARY_PATH on Mac OS X? And, what's the dynamic library search algorithm with it?

My file is in UTF8. I didn't mess around with the DYLD_LIBRARY_PATH, because a lot of sites claim it's not a good idea and I haven't understood why. It looks like it was the usual Mac OSX issue of different libraries and compilers. When I deactivated the Macports g++ and used the pre-installed g++, suddenly the problem went away. – Brendan Apr 7, 2015 at 14:48 It's not a splendid idea to do "blindly". But it is a key mechanism to do unintrusive deployments (e.g. deploying to machines that might have conflicting versions of libraries installed). the only /better/ way is to use the distro packaged version for everything - but that is usually feasibly only for very large products/very popular opensource – sehe Apr 7, 2015 at 14:51

I had the same problem of mangled directory names. I installed boost using brew install boost and gcc using brew install gcc6.

It turns out that the boost was build with the Apple's version of the GCC compiler, and the source file with the original GCC compiler. When I build your source file with Apple's compiler it does work.

Alternatively, build boost yourself with your compiler of choice.

See also the answer on a related question, https://stackoverflow.com/a/4798180/2535529.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.