Xcode 11 confuses find_package(PythonLibs)
CMake version 3.15.3 on MacOS 10.14.6 (18G103) with the following CMakeLists.txt
:
cmake_minimum_required(VERSION 3.14)
project(TEST)
find_package(PythonInterp)
find_package(PythonLibs)
message("PYTHONLIBS_VERSION_STRING: ${PYTHONLIBS_VERSION_STRING} PYTHON_VERSION_STRING ${PYTHON_VERSION_STRING}")
prints:
-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /usr/bin/python (found version "2.7.10")
-- Found PythonLibs: /usr/lib/libpython2.7.dylib (found version "2.7.16")
PYTHONLIBS_VERSION_STRING: 2.7.16 PYTHON_VERSION_STRING 2.7.10
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/axel/tmp/build
Tracing shows that the inconsistent header / library combination stems from inconsistent frameworks being used:
$ ls -l /usr/lib/libpython2.7.dylib
lrwxr-xr-x 1 root wheel 68 Jan 16 2019 /usr/lib/libpython2.7.dylib -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/Python
(which corresponds to what /usr/lib/python
will use) versus /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/python2.7/patchlevel.h
which has #define PY_VERSION "2.7.16"
. /usr/bin/python --version
says Python 2.7.10
.
Looks like Xcode delivers a MacSDK (which CMake picks up) with a python header that is newer than that on 10.14.6 (18G103).
A reasonable work-around might be to rely on the python
binary to figure out its library and include path:
from distutils.sysconfig import get_python_inc
get_python_inc()
This should guarantee a consistent answer.