简体   繁体   中英

Cmake trouble with python on windows

I tried to build C++ project using cmake on Windows. But I catch an error:

CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.3/Modules/FindPackageH
andleStandardArgs.cmake:148 (message):
  Could NOT find PythonLibs (missing: PYTHON_LIBRARIES) (found suitable
  version "3.4.1", minimum required is "3.4")
Call Stack (most recent call first):
  C:/Program Files (x86)/CMake/share/cmake-3.3/Modules/FindPackageHandleStandard
Args.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files (x86)/CMake/share/cmake-3.3/Modules/FindPythonLibs.cmake:205
(FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:8 (find_package)

Ie, cmake could not find PYTHON_LIBRARIES target. But Python 3.4.1 is installed on my PC. My OS is Windows 7 preofessional x64. If I build this project on Linux, it works fine.

Where is a problem? How can I help cmake to find PYTHON_LIBRARIES ?

Here is my CMakeLists file:

cmake_minimum_required(VERSION 3.2)
set(CMAKE_VERBOSE_MAKEFILES on)
project(Proj)
set(SOURCE_FILES repeating_count.cpp)

set(CMAKE_VERBOSE_MAKEFILE on)
set(Python_ADDITIONAL_VERSIONS 3.4.1)
find_package(PythonLibs 3.4 REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
python_add_module(repeating_count repeating_count.cpp)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_executable(Proj ${SOURCE_FILES})
target_link_libraries(Proj ${PYTHON_LIBRARIES})

I solved my issue. My default Cmake generator is Visual Studio 12 2013.

So, if I change it to Visual Studio 12 2013 Win64 (using Cmake GUI for example), it finds PYTHON_LIBRARIES target and works fine.

Try with:

find_package(PythonLibs 3.4.1 EXACT REQUIRED)

instead of

find_package(PythonLibs 3.4 REQUIRED)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM