How can I link the graphviz library into my project which is a plugin library for the kate texteditor ?

Hello,

How can I link the graphviz library into my project which is a plugin library for the kate texteditor ?

This doesn’t work:

-lgvc -lcgraph -lcdt

SET(GCC_COVERAGE_LINK_FLAGS “-lgvc -lcgraph -lcdt”)
SET(CMAKE_CXX_FLAGS  “${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}”)

SET(CMAKE_EXE_LINKER_FLAGS  “${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}”)

This works well in another project of mine, which is an apllication but the settings seems to be ignored by the compiler in my current project which is a library.
The compiler casts an undefined reference error at every command which is defined in the /usr/include/graphviz/gvc.h headerfile.
I have tried to include the headerfile with an absolute path , so I assume that the headerfile is found but the library not linked.
My other project uses the same path and it compiles and works correctly.

What is the exact syntax in order to link the graphviz library ?

They don’t seem to provide a CMake config, so you can either use a Find module made by someone else (maybe this one will work, I haven’t tested) or rely on pkg-config instead, as they do provide those, or at least that is the case in my distribution:

$ pacman -Ql graphviz | grep pc
graphviz /usr/lib/pkgconfig/libcdt.pc
graphviz /usr/lib/pkgconfig/libcgraph.pc
graphviz /usr/lib/pkgconfig/libgvc.pc
graphviz /usr/lib/pkgconfig/libgvpr.pc
graphviz /usr/lib/pkgconfig/libpathplan.pc
graphviz /usr/lib/pkgconfig/libxdot.pc

So then in CMakeLists.txt:

find_package(PkgConfig REQUIRED)
pkg_check_modules(GRAPHVIZ REQUIRED
    libcdt
    libcgraph
    libgvc
)

message(STATUS "GRAPHVIZ_INCLUDE_DIRS: ${GRAPHVIZ_INCLUDE_DIRS}")
message(STATUS "GRAPHVIZ_LIBRARIES: ${GRAPHVIZ_LIBRARIES}")

target_include_directories(${PROJECT_NAME}
    PRIVATE
        ${GRAPHVIZ_INCLUDE_DIRS}
)
target_link_libraries(${PROJECT_NAME}
    PRIVATE
        ${GRAPHVIZ_LIBRARIES}
)
# ...
-- Found PkgConfig: /usr/bin/pkg-config (found version "2.5.1")
-- Checking for modules 'libcdt;libcgraph;libgvc'
--   Found libcdt, version 14.1.5
--   Found libcgraph, version 14.1.5
--   Found libgvc, version 14.1.5
-- GRAPHVIZ_INCLUDE_DIRS: /usr/include;/usr/include/graphviz
-- GRAPHVIZ_LIBRARIES: gvc;cgraph;cdt
# ...

Thank you very much.

That solved the problem.