1

I'm working on a c++ project in xcode and I need to use the boost.

So I download the boost with brew.
Then I install the boost with the command:

brew install boost

After this, I find that the boost is installed here:

/usr/local/Cellar/

Also, the link files of all head files of boost are found:

/usr/local/include/

The lib files of boost are found:

/usr/local/lib/

Then in my project in xcode:
Build Settings ---> Search Paths ---> Header Search Paths: /usr/local/include/
Build Settings ---> Search Paths ---> Library Search Paths: /usr/local/lib/

In my project, I try codes as below:

#include <boost/thread/thread_pool.hpp>
int main(int argc, const char * argv[])
{
    return 0;
}

When I compile it, I get three errors below:

Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from: ___cxx_global_var_init.2 in main.o "boost::system::generic_category()", referenced from: ___cxx_global_var_init in main.o ___cxx_global_var_init.1 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)

Then I add /usr/local/lib/ here:
Build Setting ---> Linking ---> Other Linker Flags.
Now I get only one error:

ld: can't map file, errno=22 file '/usr/local/lib/' for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

However, the code below works well:

#include <iostream>
#include <boost/version.hpp>

int main(int argc, const char * argv[]) {

    std::cout << "Using Boost "
    << BOOST_VERSION / 100000     << "."  // major version
    << BOOST_VERSION / 100 % 1000 << "."  // minor version
    << BOOST_VERSION % 100                // patch level
    << std::endl;
    return 0;
}
Yves
  • 11,597
  • 17
  • 83
  • 180
  • An alternative to the linked question is to edit "Build Settings" --> "Linking" --> "Other Linker Flags" to include "-L/usr/local/lib -l" as you would if you were compiling the code from the command line. – Jvinniec Sep 23 '16 at 22:46
  • @Jvinniec check my new reedit please – Yves Sep 23 '16 at 22:51
  • It looks like you just added the path, which would tell the compiler to link against that directory, which doesnt make sense. Can you show me _exactly_ what you added to the "Other Linker Flags"? Also, what's the name of the library you're trying to link against? – Jvinniec Sep 23 '16 at 22:54
  • 1
    try looking at [this answer](http://stackoverflow.com/questions/5820269/c-boost-undefined-symbols-in-example) which I think might be more instructive. Trying adding `-L/usr/local/lib -lboost_system-mt` to "Other Linker Flags" – Jvinniec Sep 23 '16 at 23:03
  • @Jvinniec Thanks a lot. – Yves Sep 24 '16 at 10:04

0 Answers0