Search code examples
c++graphviz

How to Link Graphviz Lib When Compile C++ program


When I compile C++ program I occurred error as below

ubuntu@VM-20-15-ubuntu:~/MyLLVM$ g++ graphviz.cpp -o MyGraphviz -lgraphviz
/usr/bin/ld: cannot find -lgraphviz: No such file or directory
collect2: error: ld returned 1 exit status

I have install graphviz by the three commands:

sudo apt-get install graphviz
sudo apt-get install graphviz-dev
sudo apt-get install libgraphviz-dev

And I use "sudo find / -name libgraphviz" to find where the .so or .a file are,but it prints nothing on the terminal,so why I install graphviz defeat even after the 3 commands? I don't find any guidence on the graphviz official websiteWhere can I find the document of install graphviz lib on Ubuntu 24.04 LTS?


Solution

  • See appendix A of https://graphviz.org/pdf/libguide.pdf

    For linking, the application should use the Graphviz libraries

    • gvc
    • cgraph
    • cdt

    If the system is configured to use plug-ins, these libraries are all that are necessary. At run time, the program will load the dynamic libraries it needs.

    If the program does not use plug-ins, then these libraries need to be incorporated at link time. These libraries may include

    • gvplugin core
    • gvplugin dot layout
    • gvplugin neato layout
    • gvplugin gd
    • gvplugin pango

    The is no libgraphviz library, you therefore need -lgvc -lcgraph -lcdt on your linker command line (I've not used graphviz myself, -lgvc may be all you need depending on which functions you're calling).

    See also https://askubuntu.com/questions/32507/how-do-i-get-a-list-of-installed-files-from-a-package for how to get the files installed by a package, e.g. dpkg-query -L libgraphviz-dev should give you the installed library names.