Python3,Boost-Python和Cpp链接器错误
所以我准备把笔记本电脑从窗户里扔出窗外,去烧掉Apple HQ.
请参阅下面的更新: 我无法让python3,boost-python和clang互相合作.我遇到的错误正在运行: clang++ <FLAGS/INCLUDES> -o hello.so hello.cpp 调用响应: 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 非常感谢任何帮助.我想我已经包含了所有必要的东西.如果您需要额外信息,请与我们联系. 设置: > OSX 10.11.6(El Capi-s#@%) > brew install python3 >使用Boost-Python(安装了Homebrew) > brew安装加速 >使用LLVM 3.9.0(安装了Homebrew) > brew install llvm –universal 现在您可以要求一些有用的东西: Clang: 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 makefile中的FLAGS和INCLUDES: 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 最后,我正在尝试编译的代码: HELLO.CPP #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) ; }; 解决方法
经过多次心痛和痛苦,我有了答案!
对于那些使用OSX和自制程序的人来说,这就是你如何做到的. > brew install python3 Python3具有UCS4本机(Unicode),这是此过程的重要部分.如果你需要Python2,那么确保它是为UCS4配置的,因为它本身就是UCS2. 我的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) 然后你需要做的就是运行带有所有内容的makefile,一切都应该是甜蜜的:)我希望这可以帮助某人并消除我试图让insertProfanity提升工作的痛苦. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |