所以我要把我的笔记本电脑扔到窗外,然后去烧掉苹果总部。
见下面的更新:
我不能让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任何帮助都是非常非常感谢的。我想我已经包括了一切必要的东西。如果你需要额外的信息,请告诉我。
设置:
brew install python3which python -> /usr/bin/python
brew install boostbrew install boost-python --with-python3 --without-python
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中包括:
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)
;
};发布于 2016-12-08 03:21:11
在经历了许多心痛之后,我有了答案!
对于所有使用OSX和自制软件的用户,您可以这样做。
brew install python3 Python3具有UCS4本机(Unicode),这是此过程的一个重要部分。如果您需要Python2,那么确保它是为UCS4配置的,因为它本身就是UCS2。brew install boost首先安装通用boost。brew install boost-python --with-python3 --without-python为Python3安装boost-python,而不使用Python2。如果需要Python2,可以更改这些选项。brew install llvm --universal确保安装了llvm,它应该包含clang++,这是我们将要使用的编译器(而不是Xcode 1)。我的制作文件:
# 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 boost工作所带来的痛苦。
发布于 2016-11-22 07:22:55
没有足够的点来评论,所以不幸的是,我将不得不张贴作为一个答案,因为不久之前,我正在经历同样的链接器错误的东西与Boost。
我猜这似乎是Python链接器问题,而不是Boost链接器问题。我看到您已经将Python添加到您的CXX_INCLUDE_PATH中,但是您的Python库呢?
如果前面提到的路径( CXX_INCLUDE_PATH变量中的长路径)是包含的位置,那么[that_long_path]/Versions/3.5/lib应该位于您的库中。在运行build命令时,使用
clang++ -g -v -std=c++11 -stdlib=libc++ -L/[that_long_path]/Versions/3.5/lib -lpython3.5m hello.cpp -o hello.so -L标志告诉编译器包含该目录,而-l标志告诉编译器包含以下库。或者,您只需将此lib路径附加到当前的CXX_INCLUDE路径,然后如下所示:
export CXX_INCLUDE_PATH="/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/include/python3.5m:/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib"此外,在运行build命令时,请确保包含任何相关的boost包含路径和库路径,以避免更多链接器错误(如果boost没有安装在默认位置,如usr/local/[some_place] )。
然后运行这个新的构建命令(可以不使用-std and -stdlib标志:
clang++ -g -v -std=c++11 -stdlib=lib++ -lpython3.5m -o hello.so hello.cpp摘要: 1)包含您的python头文件(您似乎已经做过),2)包括您的python库文件(您似乎缺少) 3)包含任何相关的boost库和boost include目录(这在这个问题的范围之外,但仍然值得注意)
希望这能有所帮助。
https://stackoverflow.com/questions/40732947
复制相似问题