views:

50

answers:

2

Am working on a program that will allow a graph of nodes to be displayed and then updated visually as the nodes themselves are updated. I am fairly new to Visual Studio 2010 and am following the GraphViz guide located at http://www.graphviz.org/pdf/libguide.pdf in order to get GraphViz working as a library. I have the following code which is taken straight from the pdf linked above.

#include <graphviz\gvc.h>
#include <graphviz\cdt.h>
#include <graphviz\graph.h>
#include <graphviz\pathplan.h>
using namespace std;


    int main(int argc, char **argv)
    {
    Agraph_t *g;
    Agnode_t *n, *m;
    Agedge_t *e;
    Agsym_t *a;
    GVC_t *gvc;

    /* set up a graphviz context */
    gvc = gvContext();

    /* parse command line args - minimally argv[0] sets layout engine */
    gvParseArgs(gvc, argc, argv);

    /* Create a simple digraph */
    g = agopen("g", AGDIGRAPH);
    n = agnode(g, "n");
    m = agnode(g, "m");
    e = agedge(g, n, m);

    /* Set an attribute - in this case one that affects the visible rendering */
    agsafeset(n, "color", "red", "");

    /* Compute a layout using layout engine from command line args */
    gvLayoutJobs(gvc, g);

    /* Write the graph according to -T and -o options */
    gvRenderJobs(gvc, g);

    /* Free layout data */
    gvFreeLayout(gvc, g);

    /* Free graph structures */
    agclose(g);

    /* close output file, free context, and return number of errors */
    return (gvFreeContext(gvc));
    }

After compiling I get the following errors which indicate that I do not have it correctly linked.

1>main.obj : error LNK2019: unresolved external symbol _gvFreeContext referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _agclose referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _gvFreeLayout referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _gvRenderJobs referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _gvLayoutJobs referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _agsafeset referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _agedge referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _agnode referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _agopen referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _gvParseArgs referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _gvContext referenced in function _main

Within the VC++ Directories I have

C:\Program Files (x86)\Graphviz2.26.3\include in the Include Directories

and

C:\Program Files (x86)\Graphviz2.26.3\lib\release\lib in the Library Directories

Any help would be greatly appreciated to help get this working. Thank you.

+1  A: 

You normally need to add the .lib file to the additional input in the first section of the linking area.

Correction: properties->Linker->Input->Additional Dependencies.

Noah Roberts
I just added these and now the errors go away and it successfully compiles, but when I try to run the program I get the following error: "The program can't start because graph.dll is missing from your computer. Try reinstalling the program to fix this problem."I have the graph.dll linked through the additional dependencies so I don't really know what else to do.
DistortedLojik
@DistortedLojik You've probably added graph.lib/graphviz.lib through the additional dependencies and not graph.dll - and that was info for the linker. The graph.dll is not found by the OS, so put graph.dll somewhere where the OS can find it, like the System directory (i.e. C:/Windows/System32 on my 32 bit XP) [see here http://msdn.microsoft.com/en-us/library/ms682586%28VS.85%29.aspx about Windows dll search order].
Eugen Constantin Dinca
The graph.dll file just needs to be in the PATH variable or in the directory that contains the exe.
Noah Roberts
+1  A: 

Under additional library inputs, you must add the graphviz import library, whatever it's called, that's in the lib dir you added the path to. Perhaps graphviz.lib?

Johann Gerell