我正在尝试从https://github.com/TNG/boost-python-examples构建项目,这是Yosemite上的一组boost python示例。
首先我安装了Boost和Boost python和cmake
brew install boost
brew install boost-pyton
brew install cmake
我遇到了以下错误:
/usr/local/Cellar/cmake/3.0.2/bin/cmake -H/Users/demo/devel/boost-python-examples -B/Users/demo/devel/boost-python-examples/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.0.2/bin/cmake -E cmake_progress_start /Users/demo/devel/boost-python-examples/build/CMakeFiles /Users/demo/devel/boost-python-examples/build/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f 01-HelloWorld/CMakeFiles/hello.dir/build.make 01-HelloWorld/CMakeFiles/hello.dir/depend
cd /Users/demo/devel/boost-python-examples/build && /usr/local/Cellar/cmake/3.0.2/bin/cmake -E cmake_depends "Unix Makefiles" /Users/demo/devel/boost-python-examples /Users/demo/devel/boost-python-examples/01-HelloWorld /Users/demo/devel/boost-python-examples/build /Users/demo/devel/boost-python-examples/build/01-HelloWorld /Users/demo/devel/boost-python-examples/build/01-HelloWorld/CMakeFiles/hello.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f 01-HelloWorld/CMakeFiles/hello.dir/build.make 01-HelloWorld/CMakeFiles/hello.dir/build
Linking CXX shared module hello.so
cd /Users/demo/devel/boost-python-examples/build/01-HelloWorld && /usr/local/Cellar/cmake/3.0.2/bin/cmake -E cmake_link_script CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/c++ -g -bundle -Wl,-headerpad_max_install_names -o hello.so CMakeFiles/hello.dir/hello.cpp.o /usr/local/lib/libboost_python-mt.dylib
Undefined symbols for architecture x86_64:
"_PyString_Type", referenced from:
boost::python::to_python_value<char const* const&>::get_pytype() const in hello.cpp.o
"__Py_NoneStruct", referenced from:
boost::python::api::object::object() in hello.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [01-HelloWorld/hello.so] Error 1
make[1]: *** [01-HelloWorld/CMakeFiles/hello.dir/all] Error 2
make: *** [all] Error 2
看起来像是在呼唤:
/usr/bin/c++ -stdlib=libstdc++ -g -bundle -Wl,-headerpad_max_install_names -o hello.so CMakeFiles/hello.dir/hello.cpp.o /usr/local/lib/libboost_python-mt.dylib
我尝试了以下内容:
-stdlib=libstdc++
gcc
代替c++
-m32
(糟糕的主意)据我所知,dynlib很好:
/usr/local/lib/libboost_python-mt.dylib: Mach-O 64-bit dynamically linked shared library x86_64
所以我不确定我目前的问题在哪里。我假设它有某种构建标志,我在这里失踪。
谢谢!
答案 0 :(得分:2)
您还需要链接Python库。
在您的CMakeLists.txt中,您可以添加
include(FindPythonLibs)
这将定义一个变量PYTHON_LIBRARIES
,您可以像这样使用
target_link_libraries(your_exe ${PYTHON_LIBRARIES ...)
答案 1 :(得分:0)
尝试强制cmake
使用正确的目录:
cmake -DBOOST_ROOT=xxx -DPYTHON_LIBRARY=xxx -DPYTHON_INCLUDE_DIR=xxx ..