0

I have spent about 8 hours (no joke) trying to get filesystem into my XCode 6.0 project. I have exhausted my Googling and all the Stack Overflow threads on the matter.

I will try to give you as much information as possible so that you can offer suggestions if you have any.

  1. I have followed these instructions for downloading and executing tar --bzip2 -xf /path/to/boost_1_57_0.tar.bz2 on the Unix terminal. As far as I know, everything went fine.
  2. I have added #include <boost/filesystem.hpp> to the appropriate place in my program. I had set my Header Search Paths appropriately (although now I can't remember where it was that I set those. XCode is so unintuitive!)
  3. Compiled the library a la step 5 in the instructions
  4. In my thread here, I was told to "link with the boost_system library" and "don't forget -lboost_filesystem". So I went to Build Settings and tried my best to include those. I've tried various combinations, and am still not sure what the heck I'm doing. See the screenshot here.
  5. When I try to compile my program, the error I get is

    ld: library not found for -llibs_system clang: error: linker command failed with exit code 1 (use -v to see invocation)

But I know something is correct because if I move all those flags then I get 3 errors:

Undefined symbols for architecture x86_64:
  "boost::system::system_category()", referenced from:
      ___cxx_global_var_init2 in main.o
  "boost::system::generic_category()", referenced from:
      ___cxx_global_var_init in main.o
      ___cxx_global_var_init1 in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The structure of my boost_1_57_0 folder is

boost_1_57_0
    boost
        algorithm
        align 
            align.hpp
            aligned_alloc.hpp
            .
            .
        align.hpp
            .
            .
        aligned_storage.hpp
            .
            .
        .
        .
        .
    libs
        accumulator
            doc
            example
            index.html
            test
        algorithm
            .
            .
        align
            .
            .
            .
        .
        .
        .
    .
    .
    .
Community
  • 1
  • 1
  • Did you compile boost itself or just un-zipped it? You need to compile the library, see sec. 5 of the instuctions you posted. – vsoftco Feb 07 '15 at 19:21
  • Yes, I compiled it. Let me edit my main post. – Steve Ballmer Feb 07 '15 at 19:26
  • you need to use `boost_system`, not `libs_system`, as you show in your screenshot. Also you need to specify the path to the libs, as XCode doesn't know implicitly where to find them. Best thing is to compile the program from the command line, `g++ -L/path/to/boost/libs -lboost_system -lboost_filesystem test.cpp` – vsoftco Feb 07 '15 at 19:28
  • forgot to add that you also need `-I /path/to/boost` for the `#include`s to work. – vsoftco Feb 07 '15 at 19:36
  • @vsoftco system is in my libs folder but not my boost folder. Any idea why that might be? – Steve Ballmer Feb 07 '15 at 19:36
  • See the updated answer, your default path to the libs is `boost_1_57_0/stage/lib` – vsoftco Feb 07 '15 at 19:52

3 Answers3

1

Got it! The same problem happened to me and I fixed it by linking an additional library. Navigate to the XCode Targets > Build Phases > Link Binary With Libraries section and add libboost_system.dylib as well as libboost_filesystem.dylib. My version of XCode is 7.2.1.

corticalhazard
  • 189
  • 2
  • 6
0

Assuming you compiled boost, you can try the following:

#include <iostream>
#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;
}

On my system, I compile the program with

g++ -I ~/boost_1_57_0/ -L ~/boost_1_57_0/stage/lib/ -lboost_system -lboost_filesystem fs.cpp

You then need to add ~/boost_1_57_0/stage/lib/ to your DYLD_LIBRARY_PATH (otherwise OSX doesn't know how to find the dynamic library, even if you specified the path with -L), so type from the command line

export DYLD_LIBRARY_PATH=~/boost_1_57_0/stage/lib/

(there is a way to do this in XCode also, but not sure exactly how now).

Then just launch the program.

A final workaround is to install boost via macports, it will put everything into /opt/local, and won't require to export the DYLD_LIBRARY_PATH as /opt/local/lib is in the path. Or, specify /usr/local/lib as the installation directory when using bootstrap.sh to build boost.

vsoftco
  • 55,410
  • 12
  • 139
  • 252
0

My guess is that when you

"Compiled the library a la step 5 in the instructions"

you didn't compile the Boost System library (or else you'd have said "the libraries").

Common practice is to build all libraries (sometimes excluding unsupported items, but bootstrap.sh/b2 is likely able to detect this for you).

Also, Re. screenshot, it's

-lboost_system -lboost_filesystem

not -llibs_system

sehe
  • 374,641
  • 47
  • 450
  • 633