Loading problems with the demo code on Ubuntu 12.04, 13.10


Newbie here. I built the latest source code from the download page and tried to build the demo code referenced in the Graphviz as a library guide. When I run make, I get "undefined" reference errors for all the graphviz method calls. The loader does not seem to work. I built the code on a debian VM and it worked just fine; but when I try to make the code on Ubuntu 12.04 (both 32-bit and 64-bit) as well as 13.10, I get these loader errors. Here are the exact errors I am getting:
~/Downloads/graphviz-2.36.0/dot.demo$ make
cc `pkg-config libgvc --libs` dot.o -o dot
dot.o: In function `main':
/home/lgarcia/Downloads/graphviz-2.36.0/dot.demo/dot.c:21: undefined reference to `gvContext'
/home/lgarcia/Downloads/graphviz-2.36.0/dot.demo/dot.c:22: undefined reference to `gvParseArgs'
/home/lgarcia/Downloads/graphviz-2.36.0/dot.demo/dot.c:26: undefined reference to `gvFreeLayout'
/home/lgarcia/Downloads/graphviz-2.36.0/dot.demo/dot.c:27: undefined reference to `agclose'
/home/lgarcia/Downloads/graphviz-2.36.0/dot.demo/dot.c:29: undefined reference to `gvLayoutJobs'
/home/lgarcia/Downloads/graphviz-2.36.0/dot.demo/dot.c:30: undefined reference to `gvRenderJobs'
/home/lgarcia/Downloads/graphviz-2.36.0/dot.demo/dot.c:24: undefined reference to `gvNextInputGraph'
/home/lgarcia/Downloads/graphviz-2.36.0/dot.demo/dot.c:33: undefined reference to `gvFreeContext'
collect2: error: ld returned 1 exit status
make: *** [dot] Error 1

I've been stuck on this issue for over a day now trying out different versions of the code and I can't seem to find any blog posts with the same issue. I have also tried using the api in general while referencing the libraries installed when I install the debian packages using apt-get. I have also tried almost every combination of the libraries returned from pkgconfig as well as other combinations I found online. We even compiled the code statically and then linked the code to the paths of the library files. There were no errors when I built and installed the code. Any help would be greatly appreciated. I apologize if I am doing something very stupid here.

Best Regards,


I have already tried replacing pkg-config in the makefile

Thank you for your reply. I did try that and placed the following libs directly in the makefile:

-lgvc -lcgraph -lcdt

I also tried directly including "-L/usr/local/lib" option as well but had no success. The code worked perfectly when I set it up on my Debian 32-bit VM. However, I need to get it working on a Ubuntu 12.04 32-bit desktop. 

So you are running  cc

So you are running

 cc -L/usr/local/lib -lgvc -lcgraph -lcdt dot.o -o dot

and are still getting those link errors? If so, then either 1) the graphviz libraries weren't installed in /usr/local/lib, or 2) somehow the libraries are corrupted and the linker can't find the symbols, or 3) Ubuntu has some totally different linking convention.

You can check 1) by verifying that /usr/local/lib/contains libgvc.so, libcgraph.so, and libcdt.so, recently installed, and if they exist, you can check 2) by running nm on the libraries and seeing if the missing symbols are defined in the libraries. If those two check out, that leaves 3). Does the dot program work? If so, you can compare what happens when dot is built in cmd/dot with your build command.

Still not working

I have verified that the libraries are in the right place and the symbols are indeed defined in the libraries. The dot program does compile and the tool works. Below is the output of the compilation and below that are tidbits from the Makefile for cmd/dot:

make Output:

  CC       dot-dot.o
  CC       dot-no_builtins.o
  CCLD     dot
  CC       dot_builtins-dot.o
  CC       dot_builtins-dot_builtins.o
  CCLD     dot_builtins

Makefile tidbits:


CC = gcc

CFLAGS = -g -O2 -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wall -ffast-math

CPPFLAGS =  -I/usr/local/include



DEFAULT_INCLUDES = -I. -I$(top_builddir) -I$(top_builddir)/lib/common

        -I$(top_srcdir)/lib/common \
        -I$(top_srcdir)/lib/gvc \
    -I$(top_srcdir)/lib/pathplan \
    -I$(top_srcdir)/lib/cgraph \


The problem is that loader on

The problem is that loader on Ubuntu apparently uses the old linear model of linking libraries, which is very order dependent. That is, it appears to resolve symbols using definitions found after use. So, doing

cc -L/usr/local/lib -lgvc -lcgraph -lcdt dot.o -o dot

it finds unresolved symbols in dot.o, but there are no libraries after it to fit the symbols. However, if you do

 cc  dot.o -o dot -L/usr/local/lib -lgvc -lcgraph -lcdt

the linking works fine. There may be some flag for the linker to order-independent semantics, but I don't see it immediately. In any case, this should fix your problem

That worked!

Wow I've never run into an issue like that before. How weird. Anyways, thanks for your help, you saved the day! 

Run   pkg-config libgvc


  pkg-config libgvc --libs

by itself and see what you get. You should see something like

  -L/opt/local/lib -lgvc -lcgraph -lcdt

where the -L will point to where you have installed the graphviz library. If not, it may just be a matter of setting the PKG_CONFIG_PATH environment variable to pkg-config can find the correct .pc file.

Or you can just replace the `pkg-config libgvc --libs` line with the line above modified for your installation.

Recent comments