简体   繁体   中英

OSX El Capitan C++ boost and Xcode fails building project

I have been desperately looking around the internet to find a workaround for my C++ boost project to work on my OSX El Captian. here is the simple code I'm trying to compile:

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

using namespace boost::python;

int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}

Keeps failing to with this ERROR:

Undefined symbols for architecture i386:
"__Py_NoneStruct", referenced from:
  boost::python::api::object::object() in main.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have installed boost library via homebrew and defined the correct Header and Lib path in my Xcode project. I also tried different combination of build settings hoping the project would build. NO LUCK!!! Any help is appreciated.

First make sure you have installed boost using homebrew like this

brew install boost-python

otherwise the installed boost doesn't have the boost python library.

Then you need to add

-lboost_python 

in your compile script

and also link to python libraries as well. To link to python you may need to pass

-lpython

too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM