Xcode 12 command line tools and python
Hi,
$ cmake --version
cmake version 3.18.4
...
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(pycmdlntls)
find_package(Python3 COMPONENTS Development)
add_executable(pycmdlntls pycmdlntls.cxx)
target_include_directories(pycmdlntls PUBLIC ${Python3_INCLUDE_DIRS})
target_link_libraries(pycmdlntls LINK_PUBLIC ${Python3_LIBRARIES})
$ cat pycmdlntls.cxx
#include "Python.h"
int main() {
PyObject *t;
t = PyTuple_New(3);
PyTuple_SetItem(t, 0, PyLong_FromLong(1L));
PyTuple_SetItem(t, 1, PyLong_FromLong(2L));
PyTuple_SetItem(t, 2, PyUnicode_FromString("three"));
return 0;
}
$ mkdir obj; cmake ..
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python3: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 (found version "3.8.2") found components: Development Development.Module Development.Embed
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/sftnight/build/AXEL/pycmdlntls/obj
$ make
Scanning dependencies of target pycmdlntls
[ 50%] Building CXX object CMakeFiles/pycmdlntls.dir/pycmdlntls.cxx.o
[100%] Linking CXX executable pycmdlntls
[100%] Built target pycmdlntls
So far so good! See the CommandLineTools
coming with Xcode 12 now have Python3. But the resulting binary seems unusable:
$ ./pycmdlntls
dyld: Library not loaded: @rpath/Python3.framework/Versions/3.8/Python3
Referenced from: /Users/sftnight/build/AXEL/pycmdlntls/obj/./pycmdlntls
Reason: image not found
zsh: abort ./pycmdlntls
Is that something that CMake could work around? I think it's unfortunate that I need to veto CommandLineTools' Python as a CMake user, given this fundamental issue of "can find but can't use".
Or is there something I'm doing wrong? (Or is this already addressed in a later version?)
Cheers, Axel.
Edited by Ben Boeckel