Pregunta

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?

¿Fue útil?

Solución

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top