Replies: 2 comments
-
|
The intrusive reference counting code doesn't depend on nanobind (besides the header file). You just need a way to determine the path to the header.. which is not a nanobind issue. |
Beta Was this translation helpful? Give feedback.
-
|
The author already pointed at the answer in their comment - you just need the header path, not a CMake target named For your specific case (intrusive ref counting), that's actually the designed situation. From the comment at the top of
So you really do only need the include directory. nanobind's CMake config find_package(nanobind CONFIG REQUIRED)
# Pure header inclusion - no link to nanobind, no Python dependency.
target_include_directories(mylib PRIVATE ${NB_DIR}/include)
# The bindings module side stays as it was.
nanobind_add_module(mylib_module ...)
target_link_libraries(mylib_module PRIVATE mylib)After this, If add_library(nanobind::headers INTERFACE IMPORTED)
target_include_directories(nanobind::headers INTERFACE ${NB_DIR}/include)
target_link_libraries(mylib PRIVATE nanobind::headers)
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a working CMake project that uses nanobind to create a module,
mylib_module. The bindings module links a C++ librarymylib, which contains all of the non-binding logic. So,mylib_moduleis created usingnanobind_add_module, andmylibis creating usingadd_libraryI want to use intrusive reference counting, which requires modifying the types in
mylib, butmylibdoesn't link to nanobind. How do I get around this? I tried simply usingtarget_link_libraries, i.e.:but nanobind isn't recognized as a target:
I've tried various permutations, like
nanobind::nanobind, but no dice.Edit:
I am able to link to nanobind if I disable my
set(CMAKE_LINK_LIBRARIES_ONLY_TARGETS ON)check, but this still doesn't give me the header I want:Edit 2:
I seem to have made progress with:
However, I sourced this variable from this thread., so I'm sure this is not the correct approach.
For what it's worth, this compiles fine, but Python is still garbage collecting the object, causing a SEGFAULT. I followed all the instructions here, so I'm not sure where to go from here.
Beta Was this translation helpful? Give feedback.
All reactions