Build issue: System-wide install of pybind11 interferes
Hi, my system has pybind11 installed in a global include dir, which apparently takes precedence over the local copy of pybind11. It leads to this sort of compile error:
[...]
In file included from /Users/mh/src/OpenFlipper-IGM/OpenFlipper/PythonInterpreter/PyLogHook.h:32:
In file included from /opt/homebrew/include/pybind11/pybind11.h:13:
[...]
In file included from /opt/homebrew/include/pybind11/detail/../attr.h:13:
/opt/homebrew/include/pybind11/detail/common.h:479:16: error: redefinition of 'ssize_t_cast'
inline ssize_t ssize_t_cast(const IntType &val) {
^
/Users/mh/src/OpenFlipper-IGM/OpenFlipper/libs_required/ACG/../pybind11/include/pybind11/detail/common.h:483:16: note: previous definition is here
inline ssize_t ssize_t_cast(const IntType &val) {
Why does it happen - include folder precedence
At least with gcc and clang, the specified include dirs have left-to-right preference, i.e., earlier has precedence.
The corresponding commandline includes -isystem /opt/homebrew/include
, and later -isystem /Users/mh/src/OpenFlipper-IGM/OpenFlipper/libs_required/pybind11/include
. Folders specified by -I
take precedence, which is probably what we would like to use for the vendored copy of pybind11.
The cause for CMake to use -i system
instead of -I
is the combination of
# Check if pybind11 is being used directly or via add_subdirectory
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
[...]
else()
set(PYBIND11_MASTER_PROJECT OFF)
set(pybind11_system SYSTEM)
endif()
and
target_include_directories(
pybind11_headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${pybind11_INCLUDE_DIR}>
in OpenFlipper/libs_required/pybind11/CMakeLists.txt
.
Fix?
Patching that file to just set(pybind11_system "")
results in a successful build for me, but I'm not certain this is the best kind of fix.