# Error lnk2019 external symbol

**URL:** <https://igraph.discourse.group/t/error-lnk2019-external-symbol/490>\
**Category:** Usage\
**Tags:** C\
**Created:** [21 October 2020 14:23 UTC](https://igraph.discourse.group/t/error-lnk2019-external-symbol/490 "2020-10-21T14:23:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cristian\_Carcamo](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/cristian_carcamo/32/386_2.png) [@Cristian\_Carcamo](https://igraph.discourse.group/u/Cristian_Carcamo)\
**Post date:** [21 October 2020 14:23 UTC](https://igraph.discourse.group/t/error-lnk2019-external-symbol/490/1 "2020-10-21T14:23:52Z")

</div>

Visual Studio arroja el error LNK2019. ¿Quién me puede ayudar como resolver este error?  
Adjunto los errores que arroja Visual Studio.

```auto
1>ConsoleApplication1.obj : error LNK2019: símbolo externo igraph_rng_seed sin resolver al que se hace referencia en la función main
1>ConsoleApplication1.obj : error LNK2019: símbolo externo igraph_rng_default sin resolver al que se hace referencia en la función main
1>ConsoleApplication1.obj : error LNK2019: símbolo externo igraph_destroy sin resolver al que se hace referencia en la función main
1>ConsoleApplication1.obj : error LNK2019: símbolo externo igraph_erdos_renyi_game sin resolver al que se hace referencia en la función main
1>ConsoleApplication1.obj : error LNK2019: símbolo externo igraph_diameter sin resolver al que se hace referencia en la función main

```

---

<div class="post-metadata">

**Author:** ![vtraag](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/vtraag/32/38_2.png) [@vtraag](https://igraph.discourse.group/u/vtraag)\
**Post date:** [21 October 2020 14:42 UTC](https://igraph.discourse.group/t/error-lnk2019-external-symbol/490/2 "2020-10-21T14:42:26Z")

</div>

It seems that your project is unable to find the igraph C library. You must make sure that the igraph library is on the path. One way of doing so is simply copying the igraph library (`igraph.lib`) to your project directory.

Have you tested your local setup using the provided project in the `igraphtest` folder?

---

<div class="post-metadata">

**Author:** ![Ilhom\_Sadriddinov](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ilhom_sadriddinov/32/720_2.png) [@Ilhom\_Sadriddinov](https://igraph.discourse.group/u/Ilhom_Sadriddinov)\
**Post date:** [23 August 2022 03:12 UTC](https://igraph.discourse.group/t/error-lnk2019-external-symbol/490/3 "2022-08-23T03:12:36Z")

</div>

Me also getting the same kind of errors in Visual Studio 2019(16.11.18).  
When I have run this code

```auto
/* -*- mode: C -*- */
/*
   IGraph library.
   Copyright (C) 2008-2012 Gabor Csardi <csardi.gabor@gmail.com>
   334 Harvard street, Cambridge, MA 02139 USA

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   02110-1301 USA

*/

#include <igraph.h>

int print_matrix(const igraph_matrix_t* m) {
    igraph_integer_t nrow = igraph_matrix_nrow(m);
    igraph_integer_t ncol = igraph_matrix_ncol(m);
    igraph_integer_t i, j;
    igraph_real_t val;

    for (i = 0; i < nrow; i++) {
        printf("%" IGRAPH_PRId ":", i);
        for (j = 0; j < ncol; j++) {
            val = MATRIX(*m, i, j);
            if (igraph_is_inf(val)) {
                if (val < 0) {
                    printf("-inf");
                }
                else {
                    printf(" inf");
                }
            }
            else {
                printf(" %3.0f", val);
            }
        }
        printf("\n");
    }
    return 0;
}

int main() {

    igraph_t g;
    igraph_vector_t weights;
    igraph_real_t weights_data[] = { 0, 2, 1, 0, 5, 2, 1, 1, 0, 2, 2, 8, 1, 1, 3, 1, 1, 4, 2, 1 };
    igraph_matrix_t res;

    igraph_small(&g, 10, IGRAPH_DIRECTED,
        0, 1, 0, 2, 0, 3, 1, 2, 1, 4, 1, 5,
        2, 3, 2, 6, 3, 2, 3, 6,
        4, 5, 4, 7, 5, 6, 5, 8, 5, 9,
        7, 5, 7, 8, 8, 9,
        5, 2,
        2, 1,
        -1);

    igraph_vector_view(&weights, weights_data,
        sizeof(weights_data) / sizeof(weights_data[0]));

    igraph_matrix_init(&res, 0, 0);
    igraph_distances_dijkstra(&g, &res, igraph_vss_all(), igraph_vss_all(),
        &weights, IGRAPH_OUT);
    print_matrix(&res);

    igraph_matrix_destroy(&res);
    igraph_destroy(&g);

    return 0;
}

```

I am getting following errors:  
1\>------ Build started: Project: igraph, Configuration: Debug Win32 ------  
1\>1.obj : error LNK2019: unresolved external symbol \_igraph\_is\_inf referenced in function \_print\_matrix  
1\>1.obj : error LNK2019: unresolved external symbol \_igraph\_vector\_view referenced in function \_main  
1\>1.obj : error LNK2019: unresolved external symbol \_igraph\_matrix\_init referenced in function \_main  
1\>1.obj : error LNK2019: unresolved external symbol \_igraph\_matrix\_destroy referenced in function \_main  
1\>1.obj : error LNK2019: unresolved external symbol \_igraph\_matrix\_nrow referenced in function \_print\_matrix  
1\>1.obj : error LNK2019: unresolved external symbol \_igraph\_matrix\_ncol referenced in function \_print\_matrix  
1\>1.obj : error LNK2019: unresolved external symbol \_igraph\_vss\_all referenced in function \_main  
1\>1.obj : error LNK2019: unresolved external symbol \_igraph\_destroy referenced in function \_main  
1\>1.obj : error LNK2019: unresolved external symbol \_igraph\_small referenced in function \_main  
1\>1.obj : error LNK2019: unresolved external symbol \_igraph\_distances\_dijkstra referenced in function \_main  
1\>I:\Programs\igraph\igraph\Debug\igraph.exe : fatal error LNK1120: 10 unresolved externals  
1\>Done building project “igraph.vcxproj” – FAILED.  
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Could someone help me?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [23 August 2022 08:14 UTC](https://igraph.discourse.group/t/error-lnk2019-external-symbol/490/4 "2022-08-23T08:14:03Z")

</div>

This happens when your program was not linked to the igraph library. Please see the [tutorial](https://igraph.org/c/html/latest/igraph-Tutorial.html) on how to compile and link programs that use igraph. I recommend you use CMake.

If you still cannot get it to work after following the instructions in the tutorial, please explain the steps you performed to compile and link the problem. Make sure you give complete details and do not omit any step, however minor it may seem to you.

---

<div class="post-metadata">

**Author:** ![Ilhom\_Sadriddinov](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ilhom_sadriddinov/32/720_2.png) [@Ilhom\_Sadriddinov](https://igraph.discourse.group/u/Ilhom_Sadriddinov)\
**Post date:** [23 August 2022 11:48 UTC](https://igraph.discourse.group/t/error-lnk2019-external-symbol/490/5 "2022-08-23T11:48:11Z")

</div>

My OS is windows 10.

1. I installed a CMake 3.21.1.
2. Then I downloaded igraph source. From this link:  
[C/igraph 0.10.0-rc.2](https://igraph.org/2022/08/17/igraph-0.10.0-rc.2-c.html)
3. Then I created a build directory under the igraph directory.
4. Then under the build directory I run the following command:  
**cmake . .**
5. After finishing the configuration I run this command:  
**cmake --build**
6. Then I copied one example source code from igraph tutorial and pasted it into Visual Studio 2019 file
7. Once this stage is finished, I added these lines:  
**#include \<include/igraph.h\>**  
**I:\Programs\igraph\include**  
to _ **Project-\>Configuration Properties-\>VC++ Directories-\>Include Directories** _. (Please, refer to the image below)  
 ![image](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/1eb9e7ba9223c427a8388a899f1a2da996020267.png)

- So, when I compile source code without running it, it succeeded. But when I build a solution it is generating the errors that I have mentioned in the question above.

```auto
1>------ Build started: Project: igraph, Configuration: Debug Win32 ------
1>1.obj : error LNK2019: unresolved external symbol _igraph_is_inf referenced in function _print_matrix
1>1.obj : error LNK2019: unresolved external symbol _igraph_vector_view referenced in function _main
1>1.obj : error LNK2019: unresolved external symbol _igraph_matrix_init referenced in function _main
1>1.obj : error LNK2019: unresolved external symbol _igraph_matrix_destroy referenced in function _main
1>1.obj : error LNK2019: unresolved external symbol _igraph_matrix_nrow referenced in function _print_matrix
1>1.obj : error LNK2019: unresolved external symbol _igraph_matrix_ncol referenced in function _print_matrix
1>1.obj : error LNK2019: unresolved external symbol _igraph_vss_all referenced in function _main
1>1.obj : error LNK2019: unresolved external symbol _igraph_destroy referenced in function _main
1>1.obj : error LNK2019: unresolved external symbol _igraph_small referenced in function _main
1>1.obj : error LNK2019: unresolved external symbol _igraph_distances_dijkstra referenced in function _main
1>I:\Programs\igraph\igraph\Debug\igraph.exe : fatal error LNK1120: 10 unresolved externals
1>Done building project "igraph.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

```

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [23 August 2022 11:57 UTC](https://igraph.discourse.group/t/error-lnk2019-external-symbol/490/6 "2022-08-23T11:57:21Z")

</div>

You followed the instructions for compiling igraph itself, but you did not follow the instructions for [compiling your own program](https://igraph.org/c/html/latest/igraph-Tutorial.html#tut-lesson-1) correctly. You need to _link_ to the igraph library, not just set the path to the location of the header file. I am not familiar with the Visual Studio _graphical interface_, and cannot tell you how to do this in that environment. You would need to read up on this on your own. However, if you use CMake for your own project, as described in the tutorial I linked to, it will work on any platform including Windows.

If you choose not to use CMake after all and proceed on your own, keep in mind that if you compile igraph into a static library (a `.lib` file), you will need to link not only to igraph itself, but also to all its dependencies. Which these are depends on your specific configuration. It will be easier if you compile it into a shared library (a DLL), as then you only need to link to igraph. Transitive dependencies will be handled automatically. Once again, all this is relevant only if you choose not to use CMake for your own project.

---

<div class="post-metadata">

**Author:** ![Ilhom\_Sadriddinov](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/ilhom_sadriddinov/32/720_2.png) [@Ilhom\_Sadriddinov](https://igraph.discourse.group/u/Ilhom_Sadriddinov)\
**Post date:** [23 August 2022 13:36 UTC](https://igraph.discourse.group/t/error-lnk2019-external-symbol/490/7 "2022-08-23T13:36:30Z")

</div>

I tried through CMake and created CMakeLists.txt and entered the content that provided in the tutorial:

```auto
cmake_minimum_required(VERSION 3.16)
project(igraph_test)

find_package(igraph REQUIRED)

add_executable(igraph_test main.c)
target_link_libraries(igraph_test PUBLIC igraph::igraph)

```

But when I configure from CMake GUI it generated following:

 ![image](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/82f2dc44fd96be809f782d61b25d8e2fd3a0ac6d.png)  
I guess there is a problem in find\_package().  
I also tried to solve this error by searching for **igraph-config.cmake** file I found it inside of build folder. And then I changed find\_package() from CMakeLists.txt

```auto
cmake_minimum_required(VERSION 3.16)
project(igraph_test)

find_package(I:/Programs/igraph/build REQUIRED)

add_executable(igraph_test main.c)
target_link_libraries(igraph_test PUBLIC igraph::igraph)

```

But unfortunately, I got again almost the same error but this time slightly different.  
 ![image](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/962b7401c515957e6134a31670d35f9bd24bb146.png)  
What is the problem?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [23 August 2022 13:40 UTC](https://igraph.discourse.group/t/error-lnk2019-external-symbol/490/8 "2022-08-23T13:40:21Z")

</div>

Quoting from the tutorial:

> If igraph was installed at a non-standard location, specify its prefix using the `-DCMAKE_PREFIX_PATH=...` option. The prefix must be the same directory that was specified as the `CMAKE_INSTALL_PREFIX` when compiling igraph.

You need to _install_ igraph to a location of your choice (see installation instructions) and you need to point CMake to the installation location when configuring your own project.

Additionally, if you use the 0.10 release candidate, please use the docs for the development version here: [igraph Reference Manual](https://igraph.org/c/html/develop/) Now the minimum CMake version that is required is 3.18, not 3.16.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [24 August 2022 07:52 UTC](https://igraph.discourse.group/t/error-lnk2019-external-symbol/490/9 "2022-08-24T07:52:09Z")

</div>

Perhaps for you it will be simpler to do the following:

- Build a shared library, i.e. a DLL. You do this by setting `BUILD_SHARED_LIBS` to `ON` when building igraph (not when building your project). This should produce a `.dll` and and a corresponding `.lib` file.
- Try the instructions here for linking your own program to igraph: [c++ - Linking dll in Visual Studio - Stack Overflow](https://stackoverflow.com/a/7845994/695132)
