Nin*_*ils 5 c++ python macos boost
所以我要把我的笔记本电脑从窗户扔出去,从窗户上出来,去烧掉苹果总部。
请参阅下面的更新:
我无法让python3,boost-python和clang相互配合。我遇到的错误正在运行:
clang++ <FLAGS/INCLUDES> -o hello.so hello.cpp
Run Code Online (Sandbox Code Playgroud)
调用响应:
Undefined symbols for architecture x86_64:
"__Py_NoneStruct", referenced from:
boost::python::api::object::object() in hello-0c512e.o
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [hello] Error 1
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。我想我已经包括了所有必要的内容。让我知道您是否需要其他信息。
设置:
brew install python3which python -> / usr / bin / pythonbrew install boostbrew install boost-python --with-python3 --without-pythonbrew install llvm --universal现在,您可能需要一些有用的信息:
lang ++:
Apple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Run Code Online (Sandbox Code Playgroud)
Makefile中的标志和包含:
CPPFLAGS = -g -Wall -std=c++11 -stdlib=libc++
LDHEADERS = -I/usr/local/opt/llvm/include
LDLIBS = -L/usr/local/opt/llvm/lib
BOOSTHEADERS = -I/usr/local/Cellar/boost/1.62.0/include/boost
BOOSTLIBS = -L/usr/local/Cellar/boost-python/1.62.0/lib
PYTHONHEADERS = -I/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/include/python3.5m
PYTHONLIBS = -L/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib
Run Code Online (Sandbox Code Playgroud)
最后,我尝试编译的代码:
你好
#include <boost/python.hpp>
struct World
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
using namespace boost::python;
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
};
Run Code Online (Sandbox Code Playgroud)
在经历了很多心痛和痛苦之后,我有了答案!
对于所有使用OSX和自制软件的人,这是您的操作方法。
brew install python3Python3具有UCS4本机(Unicode),这是此过程的重要组成部分。如果您需要Python2,请确保为UCS4配置了它,因为它本身就是UCS2。brew install boost 首先安装常规增强。brew install boost-python --with-python3 --without-python这将在没有Python2的情况下为Python3安装boost-python。如果需要Python2,可以更改这些选项。brew install llvm --universal 确保已安装llvm,其中应包含clang ++,这是我们将使用的编译器(而不是Xcode)。我的makefile:
# compiler flags:
# -g adds debugging information to the executable file
# -Wall turns on most, but not all, compiler warnings
COMPILER = /usr/local/Cellar/llvm/3.9.0/bin/clang++
CPPFLAGS = -g -Wall -std=c++11 -stdlib=libc++
# Python and BoostPython links.
BOOSTHEADERS = -I/usr/local/Cellar/boost/1.62.0/include/boost
BOOSTLIBRARIES = -L/usr/local/Cellar/boost-python/1.62.0/lib/
# This is the boost library we want to use, there are also libraries for multithreading etc.
# All we do is find the file libboost_python3.a and link it by taking away the 'lib' and '.a'.
BOOSTLIB = -lboost_python3
PYTHONHEADERS = -I/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/include/python3.5m
PYTHONLIBRARIES = -L/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib
# Link to python3.5 library, the same as we did for boost.
PYTHONLIB = -lpython3.5
# Collect links.
LIBRARIES = $(BOOSTLIBRARIES) $(PYTHONLIBRARIES) $(PYTHONLIB) $(BOOSTLIB)
HEADERS = $(BOOSTHEADERS) $(PYTHONHEADERS)
# Build target.
TARGET = hello
# BEGIN MAKE
all: $(TARGET)
$(TARGET): $(TARGET).cpp
# Note that '-shared' creates a library that is accessible.
$(COMPILER) -shared $(LIBRARIES) $(HEADERS) $(TARGET).cpp -o $(TARGET).so
clean:
$(RM) $(TARGET)
Run Code Online (Sandbox Code Playgroud)
然后,您所需要做的就是运行包含所有包含项的makefile,一切都应该很甜:)我希望这对某人有所帮助,并消除了我试图使insertProfanityBoost正常工作的痛苦。