We have a c file called dbookpy.c, which will provide a Python binding some C functions.
Next we decided to build a proper .so with cmake, but it seems we are doing some
You need to link dbookpy against dbook:
target_link_libraries(dbookpy dbook)
Adding that just after the line ADD_LIBRARY(dbookpy dbookpy)
should do it.
I see you are using IMPORTED - the help for IMPORTED_LINK_INTERFACE_LIBRARIES
reads:
Lists libraries whose interface is included when an IMPORTED library target is
linked to another target. The libraries will be included on the link line for
the target. Unlike the LINK_INTERFACE_LIBRARIES property, this property
applies to all imported target types, including STATIC libraries. This
property is ignored for non-imported targets.
So that means that "dbook", which is in /usr/local/lib, should be an imported library:
add_library(dbook SHARED IMPORTED)
Is that really what you wanted? I mean, imported libraries are ones that are built outside CMake but are included as part of your source tree. The dbook library seems to be installed or at least expected to be installed. I don't think you need imports here - it seems to be a regular linkage problem. But this may just be a side effect of creating a minimal example to post here.
By the sounds of it, in order to get the linked libraries and link directories sorted out, I would probably use find_library()
, which will look in sensible default places like /usr/local/lib, and then append that to the link libraries.
find_library(DBOOK_LIBRARY dbook REQUIRED)
target_link_libraries(dbookpy ${DBOOK_LIBRARY})
Anyway, seems like you have it sorted now.