我正在尝试建立印利亚石墨在 VirtualBox 模拟器中运行的 ubuntu 上,我按照说明安装软件包python-dev
,但是当我运行 cmake 时,仍然出现错误:
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
(Required is at least version "3.2")
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindPythonLibs.cmake:208 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
src/packages/OGF/gel_python3/CMakeLists.txt:11 (FIND_PACKAGE)
我检查了一下,/usr/lib/
发现
tintin@tintin-VirtualBox:/usr/lib$ find . -name "libpython*"
./x86_64-linux-gnu/libpython3.4m.so.1.0
./x86_64-linux-gnu/libpython2.7.so.1.0
./x86_64-linux-gnu/libpython3.4m.a
./x86_64-linux-gnu/libpython2.7.a
./x86_64-linux-gnu/libpython3.4m.so
./x86_64-linux-gnu/libpython2.7.so
./x86_64-linux-gnu/libpython2.7.so.1
./x86_64-linux-gnu/libpython3.4m.so.1
那么为什么 cmake 找不到 PythonLibs,或者我该如何处理这个问题?
答案1
安装python-dev
实际上为我解决了这个问题:
sudo apt-get install python-dev
在这里得到提示:https://github.com/Valloric/YouCompleteMe/issues/484
答案2
问题似乎是 Ubuntu 14.04 默认安装 Python 3.4,而 Ubuntu (2.8) 的 CMake 版本仅搜索到 Python 3.3。解决方法是在语句set(Python_ADDITIONAL_VERSIONS 3.4)
前添加find_package
。请注意,我提交了一个漏洞关于这个问题。
从 CMake 3.0 开始,CMake 最高搜索 Python 3.4,因此手动安装该版本也应该可以解决问题。
答案3
对我来说,问题在于缓存不好
rm CMakeCache.txt
在我的情况下,删除了旧版本 2.7 的缓存并允许它找到 3.2 版本。
我使用的 cmake 是
find_package(PythonInterp 3.2 REQUIRED)
find_package(PythonLibs 3.2 REQUIRED)
message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")
message(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
...
include_directories(${PYTHON_INCLUDE_DIRS})
答案4
我最近遇到了与 Ubuntu 14.04 64 位类似的问题;显然,CMake 默认不会查看与体系结构相关的安装文件夹:
CMake constructs a set of possible installation prefixes for the package. Under
each prefix several directories are searched for a configuration file. The tables
below show the directories searched.
[...]
<prefix>/(lib/<arch>|lib|share)/cmake/<name>*/ (U)
<prefix>/(lib/<arch>|lib|share)/<name>*/ (U)
<prefix>/(lib/<arch>|lib|share)/<name>*/(cmake|CMake)/ (U)
[...]
In all cases the <name> is treated as case-insensitive and corresponds to any of
the names specified (<package> or names given by NAMES). Paths with lib/<arch>
are enabled if CMAKE_LIBRARY_ARCHITECTURE is set.
(来自 CMake 2.8.12 在线文档find_package 命令)
解决方案是在调用 PythonLibs 的 find_package 之前在项目根 CMakeLists.txt 文件中设置此 CMAKE_LIBRARY_ARCHITECTURE(在您的情况下,将编辑 src/packages/OGF/gel_python3/CMakeLists.txt);例如:
cmake_minimum_required(VERSION 2.8)
project(project_name)
# Check the architecture and set CMAKE_LIBRARY_ARCHITECTURE accordingly
if(UNIX)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
endif()
endif()
find_package(PythonInterp 3.2 REQUIRED)
find_package(PythonLibs 3.2 REQUIRED)
# Rest of your file
就我的情况来说,这是有效的。