3

I've been trying to use cppyy to build some python bindings for a C++ library. At the moment I am using the cookiecutter recipe from here: https://github.com/camillescott/cookiecutter-cppyy-cmake

But the package is having trouble finding LibClang_LIBRARY and LibClang_PYTHON_EXECUTABLE. This is the same case if I install cppyy with conda or pip, and importing cppyy in python works fine.

I have tried manually defining the paths with cmake -DLibClang_LIBRARY=<path/to/libclang> -DLibClang_PYTHON_EXECUTABLE=<path/to/executable> .. and although it then finds LibClang_LIBRARY, it is unable to find LibClang_PYTHON_EXECUTABLE.

It appears to be a problem with cmake finding the appropriate paths, the full error is

CMake Error at /usr/local/Cellar/cmake/3.21.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find LibClang (missing: LibClang_LIBRARY
  LibClang_PYTHON_EXECUTABLE)
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.21.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  cmake/FindLibClang.cmake:47 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  cmake/FindCppyy.cmake:286 (find_package)
  CMakeLists.txt:71 (cppyy_add_bindings)

Has anyone else found this problem or even better a solution to it?

1 Answers1

1

The cmake fragments in the cookie cutter example seem to be older than the ones in cppyy-cling: https://github.com/wlav/cppyy-backend/tree/master/cling/python/cppyy_backend/cmake

(These are the ones installed under cppyy_backend/cmake in the Python site-packages directory.)

The newer version protects the searches with a predicate in case the variables are explicitly defined as you do with the -D... option, which I suspect will then solve most of the issues you encountered.

It also uses llvm-config if available, which is more robust than trying likely directories.

Wim Lavrijsen
  • 3,453
  • 1
  • 9
  • 21