I am trying to use Pybind11 in a Cmake project. I'm using Cmake 3.23.0-rc2.
To include it, I can do the following:
find_package(pybind11 REQUIRED)
However, this does not work on my machine. So, I attempted to give find_package a hint as per the user guide:
SET(pybind11_DIR, "C:/Users/tyler.shellberg/AppData/Local/Programs/Python/Python37/Lib/site-packages/pybind11")
That did not work either. The Cmake error suggested it may need to be the specific location of files like pybind11Config.cmake
. So, I tried being more specific:
SET(pybind11_DIR, "C:/Users/tyler.shellberg/AppData/Local/Programs/Python/Python37/Lib/site-packages/pybind11/share/cmake/pybind11")
That doesn't work either. I get the exact same error in Cmake:
CMake Error at lib/(our project name)/CMakeLists.txt:30 (find_package):
By not providing "Findpybind11.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "pybind11",
but CMake did not find one.
Could not find a package configuration file provided by "pybind11" with any
of the following names:
pybind11Config.cmake
pybind11-config.cmake
Add the installation prefix of "pybind11" to CMAKE_PREFIX_PATH or set
"pybind11_DIR" to a directory containing one of the above files. If
"pybind11" provides a separate development package or SDK, be sure it has
been installed.
I double checked, Python itself is being found:
Python_FOUND:TRUE
Python_VERSION:3.7.4
Python_Development_FOUND:TRUE
Python_LIBRARIES:C:/Users/tyler.shellberg/AppData/Local/Programs/Python/Python37/libs/python37.lib
Python_INCLUDE_DIRS:
(Though weirdly, include_dirs is empty)
What am I doing wrong?
CodePudding user response:
pip install "pybind11[global]"
fixed it. It may not be recommended, but it works. Found the recommendation from here: How to make cmake find pybind11
CodePudding user response:
One way is to find Python3
first and then use the sitelib as a hint:
find_package(Python3 REQUIRED)
find_package(pybind11 REQUIRED HINTS "${Python3_SITELIB}")