Error lnk2019 external symbol

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

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

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?

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

/* -*- 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?

This happens when your program was not linked to the igraph library. Please see the tutorial 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.

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
  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)
  • 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.
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 ==========

You followed the instructions for compiling igraph itself, but you did not follow the instructions for compiling your own program 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.

1 Like

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

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:


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

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
What is the problem?

1 Like

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 Now the minimum CMake version that is required is 3.18, not 3.16.

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