0

There are many threads on this topic, but I've tried some of the solutions and nothing seems to work.

If I install boost with:

brew install booost --c++11

and try to compile the following program tut1.cpp:

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

using

clang -I /usr/local/Cellar/boost/1.55.0_1/include/ -L /usr/local/Cellar/boost/1.55.0_1/lib/ tut1.cpp 

and it fails horribly:

Undefined symbols for architecture x86_64:
"boost::filesystem::path::codecvt()", referenced from:
 boost::filesystem::path::path<char*>(char* const&,     boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<char*>::type>, void>::type*) in tut1-6a2087.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 linking seems to be the problem because if I invoke the -c option the object file gets created.

Any ideas what the hell is going on?

user1654183
  • 4,375
  • 6
  • 26
  • 33
  • 2
    Try linking the relevant libraries too, e.g. `-lboost_filesystem`. See http://stackoverflow.com/questions/13467072/c-boost-undefined-reference-to-boostsystemgeneric-category/13468280#13468280 – juanchopanza May 14 '14 at 17:42

1 Answers1

3

You want to link against boost filesystem and boost system:

-lboost_filesystem -lboost_system

So the complete compile command would be:

clang++ -I /usr/local/opt/boost/include -L /usr/local/opt/boost/lib tut1.cpp -lboost_filesystem -lboost_system
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173