Search code examples
c++ubuntugraphviz

How to properly link Graphviz in a c++ application on Ubuntu


I am having problems compiling simple example code taken from the official website here https://graphviz.gitlab.io/_pages/dot.demo/demo.c .The problem is undefined reference to Graphviz functions. I know there is a related question asked here Qt Creator cannot resolve gvContext on Ubuntu, but it didn't help.

I have included libgvc libcgraph libcdt in my CMakeLists.txt and that did't help. I have made sure that these packages are present on my machine.

Here is my CMakeLists.txt

cmake_minimum_required(VERSION 3.13)
project(name)

set(CMAKE_CXX_STANDARD 14)

add_executable(name main.cpp)

INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(gvc REQUIRED libgvc libcgraph libcdt)
LINK_DIRECTORIES(${gvc_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(${gvc_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${gvc_LIBRARIES})

Please if someone linked the library or knows how to link correctly, let me know.


Solution

  • Did you install the libgraphviz-dev package? That contains the libgvc pkg-config file your CMakeLists.txt needs.