我试图在一个Cmake项目中使用Pybind11。我使用的是Cmake3.23.0-Rc2。
为了包括它,我可以做以下几点:
find_package(pybind11 REQUIRED)
但是,这在我的机器上不起作用。因此,我试图按照用户指南给find_package一个提示:
SET(pybind11_DIR, "C:/Users/tyler.shellberg/AppData/Local/Programs/Python/Python37/Lib/site-packages/pybind11")
这也没用。Cmake建议它可能需要像pybind11Config.cmake
这样的文件的特定位置。所以,我试着说得更具体些:
SET(pybind11_DIR, "C:/Users/tyler.shellberg/AppData/Local/Programs/Python/Python37/Lib/site-packages/pybind11/share/cmake/pybind11")
这也没用。我在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.
我仔细检查了一下,就可以找到Python本身:
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:
(尽管奇怪的是,include_dirs是空的)
我做错了什么?
发布于 2022-11-07 07:42:12
一种方法是先找到Python3
,然后使用站点作为提示:
find_package(Python3 REQUIRED)
find_package(pybind11 REQUIRED HINTS "${Python3_SITELIB}")
发布于 2022-11-07 02:03:43
pip install "pybind11[global]"
修好了。它可能不是推荐的,但它是有效的。从这里找到建议:How to make cmake find pybind11
https://stackoverflow.com/questions/74341221
复制相似问题