【问题标题】:Linking Boost Python on OSX 10.10在 OSX 10.10 上链接 Boost Python
【发布时间】:2014-12-22 23:47:49
【问题描述】:

我正在尝试从: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

所以我不确定我目前的问题出在哪里。我假设它是我在这里缺少的某种构建标志。

谢谢!

【问题讨论】:

    标签: python c++ macos boost cmake


    【解决方案1】:

    您还需要在 Python 库中进行链接。

    在你的 CMakeLists.txt 你可以添加

    include(FindPythonLibs)
    

    这将定义一个变量PYTHON_LIBRARIES,然后您可以像这样使用它

    target_link_libraries(your_exe ${PYTHON_LIBRARIES ...)
    

    【讨论】:

      【解决方案2】:

      尝试强制cmake 使用正确的目录:

      cmake -DBOOST_ROOT=xxx -DPYTHON_LIBRARY=xxx -DPYTHON_INCLUDE_DIR=xxx ..
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-08-12
        • 2015-02-08
        • 2014-07-28
        • 2015-11-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-27
        相关资源
        最近更新 更多