Pybind11: find_package() not working, cant include the lib.

Created on 19 Oct 2018  路  6Comments  路  Source: pybind/pybind11

Hey

This is a little "noobish" question but I have been struggling with it for a while now. I'm trying to add pybind11 to my c++ project but I cant get past through cmake setup.

Here are the steps that I did
Download pybind
Extract it to my externalLib/pybind/pybind11 folder
Add environment path helper to find pybind so its something like ${externalLibs}/pybind/pybind11
and then did this cmake as shown below

SET(PYBIND_LIB ${externalLibs}/pybind/pybind11) set(pybind11_DIR ${PYBIND_LIB}/tools) find_package(pybind11 REQUIRED)

And that gives me this error :

`
CMake Error at CMakeLists.txt:65 (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 even tried this
find_package(pybind11 REQUIRED PATHS "C:/dev/externalLibs/pybind/pybind11/tools")
And he still does not find the stuff?!

What am I doing wrong here?!

Most helpful comment

Same tour de force here, so here it goes:

  • you install pybind11 via a subdir in your project (the default). You just need to add_subdirectory(pybind11) and pybind11_add_module(). Every check is resolved by pybind11 subdir CMakeLists.txt
  • you install out-of-path: need to go thru all manual setup by building pybind11 with cmake so that you can choose a PYBIND11_CMAKECONFIG_INSTALL_DIR to where you need. When you do cmake install, clean CMake configurations files will be created: pybind11Tools.cmake, FindPythonLibsNew.cmake, pybind11ConfigVersion.cmake
    pybind11Config.cmake, pybind11Targets.cmake
    I've installed mine into my python version of choice in shared/cmake/pybind11 but mind this is very manual and moreover not required

All 6 comments

I went over the directory again, slower... I found out that the file
pybind11Config.cmake
was in fact named
pybind11Config.cmake.in
so I renamed it, now it goes through but crashes here :
Parse error. Expected a command name, got unquoted argument with text "@PACKAGE_INIT@". Call Stack (most recent call first): CMakeLists.txt:65 (find_package

is ${externalLibs} in your project? you could use add_subdirectory(${externalLibs}/pybind/pybind11) instead of find_package

have you checked out the cmake_example project?

No its in different location.

have you checked out the cmake_example project?

Yeah I did look in to it. But my pybind11 is not inside the project. Its in generic external lib location.

I'm unable to link it/add it or test it when using find_package. Even when he finds it he just throw the error with PACKAGE_INIT listed above.

Regards
Dariusz

pybind11Config.cmake.in is a template file, and is baked into pybind11Config.cmake once you build the pybind project.

$ mkdir build
$ cd build
$ cmake ..
$ make check -j 4

After then you will find pybind11Config.cmake file in build/ directory. The problem is that I don't know what is the right way to make the baked config.cmake available from my project (via find_package) I tried to set pybind11_DIR or add the path to the CMAKE_MODULE_PATH, but it is quite cumbersome.

I'd appreciate if anyone can help us solving it.

Same tour de force here, so here it goes:

  • you install pybind11 via a subdir in your project (the default). You just need to add_subdirectory(pybind11) and pybind11_add_module(). Every check is resolved by pybind11 subdir CMakeLists.txt
  • you install out-of-path: need to go thru all manual setup by building pybind11 with cmake so that you can choose a PYBIND11_CMAKECONFIG_INSTALL_DIR to where you need. When you do cmake install, clean CMake configurations files will be created: pybind11Tools.cmake, FindPythonLibsNew.cmake, pybind11ConfigVersion.cmake
    pybind11Config.cmake, pybind11Targets.cmake
    I've installed mine into my python version of choice in shared/cmake/pybind11 but mind this is very manual and moreover not required

Thanks for answering, @kabukunz!

Was this page helpful?
0 / 5 - 0 ratings