【问题标题】:Finding the correct Python framework with cmake使用 cmake 找到正确的 Python 框架
【发布时间】:2010-12-15 15:38:08
【问题描述】:

我在 Snow Leopard 计算机上使用 macports 版本的 python,并使用 cmake 为其构建跨平台扩展。我使用 CMakeLists.txt 中的以下命令在系统上搜索 python 解释器和库

include(FindPythonInterp)
include(FindPythonLibs  )

然而,虽然 cmake 在 /opt/local/bin 中识别出正确的解释器,但它试图链接到错误的框架——即系统 Python 框架。

-- Found PythonInterp: /opt/local/bin/python2.6
-- Found PythonLibs: -framework Python

这会导致以下运行时错误

Fatal Python error: Interpreter not initialized (version mismatch?)

一旦我用/opt/local/Library/Frameworks/Python.framework/Python 替换-framework Python,事情似乎就按预期工作了。

如何针对

中找到的正确 Python 框架创建 cmake 链接
/opt/local/Library/Frameworks/Python.framework/Python

而不是系统中的一号

/System/Library/Frameworks/Python.framework/Python

?

【问题讨论】:

    标签: python frameworks macos cmake macports


    【解决方案1】:

    在~/.bash_profile中添加以下内容

    export DYLD_FRAMEWORK_PATH=/opt/local/Library/Frameworks
    

    至少暂时解决了这个问题。显然,python解释器和cmake使用的python框架之间的这种不一致是一个错误,应该希望在新版本中修复。

    【讨论】:

      【解决方案2】:

      我对 CMake 不是很熟悉,但是使用 Apple 版本的 gcc/ld,可以通过 -F 标志来指定新的框架搜索路径。例如,-F/opt/local/Library/Frameworks 将在 MacPorts 的 frameworks 目录中搜索。如果您可以使用 CMake 指定这样的标志,它可能会解决您的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-28
        • 2015-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多