# Cannot use Graphviz as lib on windows with C++

**URL:** <https://forum.graphviz.org/t/cannot-use-graphviz-as-lib-on-windows-with-c/1960>\
**Category:** Dev\
**Created:** [January 7, 2024, 12:30pm UTC](https://forum.graphviz.org/t/cannot-use-graphviz-as-lib-on-windows-with-c/1960 "2024-01-07T12:30:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SadE](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/sade/32/1302_2.png) [@SadE](https://forum.graphviz.org/u/SadE)\
**Post date:** [January 7, 2024, 12:30pm UTC](https://forum.graphviz.org/t/cannot-use-graphviz-as-lib-on-windows-with-c/1960/1 "2024-01-07T12:30:54Z")

</div>

Hi,

I’m trying to setup a usable graphviz lib setup on VS 2022. I added all the 35 lib provided in the windows zip, the header files. I can compile a little basic example, but at the linking i got this error :  
|Error|LNK2001|unresolved external symbol \_Agdirected  
This one seems to be defined in cgraph.h as “CGRAPH\_API extern Agdesc\_t Agdirected;”  
But cannot be found in one of the lib.  
I guess I missed something in the process, but looking on stack overflow, I’m not the only one 🤔

---

<div class="post-metadata">

**Author:** ![sprezzatura](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/sprezzatura/32/1815_2.png) [@sprezzatura](https://forum.graphviz.org/u/sprezzatura)\
**Post date:** [February 14, 2025, 8:09pm UTC](https://forum.graphviz.org/t/cannot-use-graphviz-as-lib-on-windows-with-c/1960/2 "2025-02-14T20:09:55Z")

</div>

Add:

```auto
#define GVDLL
#include <gvc.h>

```

See: [visual studio 2022 - Can't use Graphviz as a library in C++ - Stack Overflow](https://stackoverflow.com/questions/77733103/cant-use-graphviz-as-a-library-in-c)

---

<div class="post-metadata">

**Author:** ![sprezzatura](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/sprezzatura/32/1815_2.png) [@sprezzatura](https://forum.graphviz.org/u/sprezzatura)\
**Post date:** [October 3, 2025, 2:30pm UTC](https://forum.graphviz.org/t/cannot-use-graphviz-as-lib-on-windows-with-c/1960/3 "2025-10-03T14:30:35Z")

</div>

Here’s the missing piece to make it work with Visual Studio.

```auto
extern "C" {
#ifdef _WIN32
#define IMPORT __declspec(dllimport)
#else
#define IMPORT /* nothing */
#endif
IMPORT extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
}
gvAddLibrary(gvc, &gvplugin_dot_layout_LTX_library);

```

Thanks to Pavlo Pylypchuk, who can be contacted at [Upwork.com](http://Upwork.com)
