[gdal-dev] CMake - cross compiling - Python

Javier Jimenez Shaw j1 at jimenezshaw.com
Wed Apr 6 08:38:50 PDT 2022


Hi

We are testing CMake compilation, and we are having a problem with python,
in particular doing Cross Compilation in macOS x86_64 to M1 (arm)
architecture. Python is found, but the x86_64 (that is not usable here),
even when we disable Python bindings.

We use this options:
GDAL_USE_EXTERNAL_LIBS=OFF
GDAL_USE_GEOTIFF=ON
BUILD_PYTHON_BINDINGS=OFF

The error I get is

[ 82%] Linking CXX executable pytest_runner
ld: warning: ignoring file
/Library/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib,
building for macOS-arm64 but attempting to link with file built for
macOS-x86_64
Undefined symbols for architecture arm64:
  "_PyRun_SimpleStringFlags", referenced from:
      _main in pytest_runner.cpp.o
  "_Py_DecodeLocale", referenced from:
      _main in pytest_runner.cpp.o
  "_Py_Finalize", referenced from:
      _main in pytest_runner.cpp.o
  "_Py_Initialize", referenced from:
      _main in pytest_runner.cpp.o
  "_Py_SetProgramName", referenced from:
      _main in pytest_runner.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
make[2]: *** [autotest/pytest_runner] Error 1
make[1]: *** [autotest/CMakeFiles/pytest_runner.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

As a fix, I added an "if" statement in CMakeLists.txt ("# added line"
below) to consider the case when BUILD_PYTHON_BINDINGS is not enabled.

if (BUILD_PYTHON_BINDINGS)  # added line
if (Python_LOOKUP_VERSION)
  set(Python_FIND_STRATEGY VERSION)
  find_package(Python ${Python_LOOKUP_VERSION} EXACT COMPONENTS Interpreter
Development NumPy)
else ()
  set(Python_FIND_STRATEGY LOCATION)
  find_package(Python 3.6 COMPONENTS Interpreter Development NumPy)
endif ()
endif ()  # added line

But maybe there is a better solution.
If that is Ok for you, I can create a PR.

Best regards,
Javier

.___ ._ ..._ .. . ._.  .___ .. __ . _. . __..  ... .... ._ .__
Entre dos pensamientos racionales
hay infinitos pensamientos irracionales.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220406/79c4d70d/attachment.html>


More information about the gdal-dev mailing list