I want to embed Python into one of my applications, which is built using CMake. I do in CMakeLists.txt like this:

find_package(PythonLibs REQUIRED) include_directories(${PYTHON_INCLUDE_DIRS}) ... target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARIES}) 

Under Linux there are no problems, everything is going right away. Put Python (the latest actual version at the moment - 3.6) on Windows. When installing, I chose "Set for all users" and "Add Python to PATH variable". After installation, the Python interpreter works fine. However, CMake cannot find Python:

 CMake Error at C:/Program Files/CMake/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message): Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE) C:/Program Files/CMake/share/cmake-3.7/Modules/FindPythonLibs.cmake:255 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) CMakeLists.txt:3 (find_package) 

What could be the problem? And how to make the project build on both OSes without any problems?

    1 answer 1

    The find_package() function does not search all over your hard disk, but only in certain directories. On Linux, roughly speaking, all the libraries are in one place, so CMake easily finds them.

    On Windows, the python can be installed in any directory of any kind, so CMake must manually poke the muzzle into the desired folder. What, in fact, he said:

    Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)

    You can set these variables to the desired values, or you can set the variable CMAKE_PREFIX_PATH and specify a folder with python in it. It should work, in theory.

    • Judging by the source code, shouldn't it read the keys from the registry? - kiv_apple