[CMake] Problem calling find_package(PythonLibs) consecutively on Windows with python debug
Edison Gustavo Muenz
edisongustavo at gmail.com
Mon Apr 4 10:25:36 EDT 2016
Hi all,
The problem
I’m compiling a project in which I have:
- python bindings for C++
- VTK
When issuing a find_package(VTK) inside a FindMyLib.cmake I got this error:
CMake Error at D:/Work/Miniconda/envs/sci20/Library/share/cmake-3.4/Modules/FindPythonLibs.cmake:180
(get_filename_component):
get_filename_component unknown component
D:/Work/Miniconda/envs/sci20/libs/python27.lib
Call Stack (most recent call first):
CMakeLists.txt:15 (find_package)
CMake Error at D:/Work/Miniconda/envs/sci20/Library/share/cmake-3.4/Modules/FindPythonLibs.cmake:181
(get_filename_component):
get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
CMakeLists.txt:15 (find_package)
I pinpointed the problem to:
find_package(PythonInterp)
find_package(PythonLibs)
find_package(PythonLibs) # This call crashes
Minimum reproducible example
# CMakeLists.txt
cmake_minimum_required(VERSION 3.4.3)
project(my_project LANGUAGES CXX)
message("----------------------------------------------------------------------------")
message("1st Find Python
(${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE})")
message("-------")
find_package (PythonInterp REQUIRED)
find_package (PythonLibs REQUIRED)
message("----------------------------------------------------------------------------")
message("2nd Find Python
(${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE})")
message("-------")
find_package (PythonLibs REQUIRED)
Gives the output:
λ rm -rf * && cmake -G "Ninja" x:\etk\sci20
-- The CXX compiler identification is MSVC 16.0.40219.1
-- Check for working CXX compiler using: Ninja
-- Check for working CXX compiler using: Ninja -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
----------------------------------------------------------------------------1st
Find Python (X:/etk/sci20/CMakeLists.txt:6)
-------
-- Found PythonInterp: D:/Work/Miniconda/envs/sci20/python.exe (found
version "2.7.11")
-- Found PythonLibs:
optimized;D:/Work/Miniconda/envs/sci20/libs/python27.lib;debug;D:/Work/Miniconda/envs/sci20/libs/python27_d.lib
(found version "2.7.11")
----------------------------------------------------------------------------2nd
Find Python (X:/etk/sci20/CMakeLists.txt:12)
-------
CMake Error at D:/Work/Miniconda/envs/sci20/Library/share/cmake-3.4/Modules/FindPythonLibs.cmake:180
(get_filename_component):
get_filename_component unknown component
D:/Work/Miniconda/envs/sci20/libs/python27.lib
Call Stack (most recent call first):
CMakeLists.txt:15 (find_package)
CMake Error at D:/Work/Miniconda/envs/sci20/Library/share/cmake-3.4/Modules/FindPythonLibs.cmake:181
(get_filename_component):
get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
CMakeLists.txt:15 (find_package)
-- Found PythonLibs:
optimized;optimized;optimized;D:/Work/Miniconda/envs/sci20/libs/python27.lib;optimized;debug;optimized;D:/Work/Miniconda/envs/sci20/libs/python27_d.lib;debug;D:/Work/Miniconda/envs/sci20/libs/python27_d.lib
(found version "2.7.11")
-- Configuring incomplete, errors occurred!
See also "X:/etk/sci20/build/ninja/CMakeFiles/CMakeOutput.log".
My environment:
- Windows 7
- CMake 3.4.3 and CMake 3.5 (both showed the problem)
- Python 2.7 compiled in PYDEBUG
<https://docs.python.org/devguide/setup.html#compiling-for-debugging>
mode (python_d)
Diagnosis and workaround
The problem is that the PYTHON_LIBRARY variable at the 2nd call to
find_package(PythonLibs) is filled with:
optimized;D:/Work/Miniconda/envs/sci20/libs/python27.lib;debug;D:/Work/Miniconda/envs/sci20/libs/python27_d.lib
Which makes PythonBindings.cmake confused about what to do.
workaround
Call unset(PYTHON_LIBRARY) before any call to find_package(PythonLibs).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160404/41a58fe9/attachment-0001.html>
More information about the CMake
mailing list