# How to use OGDF library with TikZ 3.0?

I try to compile (via lualatex) the following MWE without success.

\documentclass[tikz]{standalone}
\usetikzlibrary{graphdrawing}
\usegdlibrary{ogdf}
\begin{document}
\begin{tikzpicture}
\graph [SugiyamaLayout] { a -- {b,c,d} -- e -- a };
\end{tikzpicture}
\end{document}


I got this message:

! LuaTeX error ...tex/generic/pgf/graphdrawing/lua/pgf/gd/ogdf/library.lua:32: m
stack traceback:
[C]: in function 'require'
...tex/generic/pgf/graphdrawing/lua/pgf/gd/ogdf/library.lua:32: in main chunk
[C]: in function 'require'
[string "\directlua "]:1: in function 'lookup'
[string "\directlua "]:1: in function 'pgf_lookup_and_require'
[string "\directlua "]:1: in main chunk.
\fi
l.3 \usegdlibrary{ogdf}


So, how to use OGDF library with TikZ 3.0?

Too long for a comment. In Section 34 Graph Drawing Algorithms: The Open Graph Drawing Framework, the PGF documentation has a rather discouraging message about this:

Remark: The integration of the ogdf library is still under construction and the examples in this section are more a proof-of-concept. So, use at your own risk.

and then, a few lines below:

Since C++ code is compiled and not interpreted (like Lua), in order to use the present library, you need a compiled version of the pgf interface code for the ogdf library (pgf/gd/ogdf/c/ogdf_script.so) installed correctly for your particular architecture. This is by no means trivial...

So, in order for those examples to work, you need a compiled version of pgf/gd/ogdf/c/ogdf_script.so installed correctly for your particular architecture. How to do that, I wouldn't know... I did a quick search on the web but couldn't find anything really helpful. It really seems to be not a trivial task.

• I compiled the OGDF library and the ogdf_script.so (with dynamic link) on Ubuntu. Now, LuaTeX finds pgf_gd_ogdf_c_ogdf_script.so and the error message changes but I still can not compile the examples. I will continue my tests... – Paul Gaborit Mar 13 '14 at 14:26

I was able to compile the example after adding the following line:

\usetikzlibrary{graphs}


so that the complete MWE becomes:

\documentclass[tikz]{standalone}
\usetikzlibrary{graphs}
\usetikzlibrary{graphdrawing}
\usegdlibrary{ogdf}
\begin{document}
\begin{tikzpicture}
\graph [SugiyamaLayout] { a -- {b,c,d} -- e -- a };
\end{tikzpicture}
\end{document}


If there still is a problem, you could check that there are no missing dependencies in the PGF-OGDF interface library:

ldd PATH_TO/pgf_gd_ogdf_c_ogdf_script.so


The following is a description of what worked for me on Ubuntu 12.04 x86-64.

I used the following software / library versions:

• PGF 3.0.0
• OGDF v. 2012.07
• Lua 5.2.3

# Installation

## Lua and OGDF

I installed Lua and OGDF from source to a personal, i.e. non-system directory. I followed the standard procedure, except for two adjustment to OGDF:

1. Adjusted a parameter in makeMakefile.config:

sharedLib = true

2. Removed -DOGDF_DLL from compiler options in makeMakefile.py. In the diff below, "<" is the original version and ">" the adjusted version:

85c85
<       compiler = ' '.join( [compiler, '-DOGDF_DLL -DOGDF_INSTALL' ] )
---
>       compiler = ' '.join( [compiler, '-DOGDF_INSTALL' ] )


## OGDF interface of PGF

I downloaded and unzipped the TDS archive of PGF from http://www.ctan.org/pkg/pgf .

I created a text file source/generic/pgf/c/config/LocalMakefileConfig.mk with the following contents:

LUAINCLUDES=<LUAPATH>
OGDFINCLUDES=<OGDFPATH>
INSTALLDIR=<TEXBIN>/lib/luatex/lua
MYCFLAGS=-fPIC


Note that <...> must be replaced with the appropriate values:

• <LUAPATH>, path to lua headers
• <OGDFPATH>, path to OGDF headers
• <TEXBIN>, path to TeX binaries

Alas, I could not find a way to make a local config file that would allow a simple make all to complete (because of the order of compiler options in the Makefiles). This left me with two alternatives: edit the Makefiles or compile by hand. I took the latter route.

I ran the following sequence of commands, where <LIBPATH> denotes the location of the Lua and OGDF libraries (.so). Replace it with the appropriate path. Note that -L<LIBPATH> and -rpath=<LIBPATH> are not needed if the libraries have been installed in a standard location. The idea is basically the following:

1. make all
2. if (when) there is an error, fix by hand (create a shared object, .so)
3. if there are other .so files to be made, go to 1

The command sequence:

cd source/generic/pgf/c
make all
cd graphdrawing/pgf/gd/examples/c
gcc -shared SimpleDemoC.o ../../interface/c/InterfaceFromC.o \
-L<LIBPATH> -Wl,--no-undefined,-rpath=<LIBPATH> \
-lm -llua -o SimpleDemoC.so
cd ../../../../..
make all
cd graphdrawing/pgf/gd/examples/c
g++ -shared SimpleDemoCPlusPlus.o ../../interface/c/InterfaceFromC++.o \
../../interface/c/InterfaceFromC.o -L<LIBPATH> \
-Wl,--no-undefined,-rpath=<LIBPATH> -llua \
-o SimpleDemoCPlusPlus.so
cd ../../../../..
make all
cd graphdrawing/pgf/gd/ogdf/c
g++ -shared ../../interface/c/InterfaceFromC.o \
../../interface/c/InterfaceFromC++.o InterfaceFromOGDF.o ogdf_script.o \
-L<LIBPATH> -Wl,--no-undefined,-rpath=<LIBPATH> \
cd ../../../../..
make all
cd graphdrawing/pgf/gd/ogdf/c
g++ -shared SimpleDemoOGDF.o ../../interface/c/InterfaceFromC++.o \
../../interface/c/InterfaceFromC.o InterfaceFromOGDF.o \
-L<LIBPATH> -Wl,--no-undefined,-rpath=<LIBPATH> \