Configuring CMake with graphviz library

和自甴很熟 提交于 2021-02-10 15:14:18

问题


I'm trying to make a function which will generate an image with graph from .dot file, so i have to use graphviz library, here is this function:

#include <fstream>
#include <gvc.h>

bool draw_image(const string& path) {
    GVC_t *gvc;
    Agraph_t *gr;
    FILE *fp;
    gvc = gvContext();
    fp = fopen((path + ".dot").c_str(), "r");
    gr = agread(fp, nullptr);
    gvLayout(gvc, gr, "dot");
    gvRender(gvc, gr, "png", fopen((path + ".png").c_str(), "w"));
    gvFreeLayout(gvc, gr);
    agclose(gr);
    return (gvFreeContext(gvc));
}

I'm using clion IDE and cmake, so here is my CMakelists.txt:

cmake_minimum_required(VERSION 3.16)
project(untitled)

set(CMAKE_CXX_STANDARD 14)

INCLUDE_DIRECTORIES(SYSTEM "/usr/include/graphviz/")

add_executable(untitled main.cpp)

TARGET_LINK_LIBRARIES(untitled LINK_PUBLIC "/usr/lib/x86_64-linux-gnu/libcgraph.so")

The problem is that when I build the project, I get errors like undefined reference to 'gvContext'

But clion can see this functions and refers to gvc.h properly, so I think the problem is in CMakeLists.txt

I can't understand how to properly refer to an external library in CMake and which file to specify. So how should I do that?


回答1:


gvContext is in libgvc.so, so your final CMake line should read:

target_link_libraries(untitled PUBLIC cgraph gvc)

This makes use of the "A plain library name" section of the target_link_libraries documentation.



来源:https://stackoverflow.com/questions/61771170/configuring-cmake-with-graphviz-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!