failed to run walktrap algorithm in C++ error while loading shared libraries: ?: cannot open shared object file: No such file or directory

This is the error I got:

D:/face_recongition/learn-to-cluster-master/igraph-example-master/cmake-project/build/runWalktrap.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

This is the cmake file:

cmake_minimum_required(VERSION 3.18)

find_package(igraph REQUIRED)

add_executable(runWalktrap runWalktrap.c)
target_link_libraries(runWalktrap PUBLIC igraph::igraph)

This is the walktrap code:

#include <igraph.h>

int main(void) {
    igraph_t g;
    igraph_matrix_int_t merges;
    igraph_vector_t modularity;
    igraph_integer_t no_of_nodes;
    igraph_integer_t i;

    igraph_small(&g, 5, IGRAPH_UNDIRECTED,
                 0, 1, 0, 2, 0, 3, 0, 4, 1, 2, 1, 3, 1, 4, 2, 3, 2, 4, 3, 4,
                 5, 6, 5, 7, 5, 8, 5, 9, 6, 7, 6, 8, 6, 9, 7, 8, 7, 9, 8, 9, 0, 5, 4, 9, -1);
    igraph_vector_init(&modularity, 0);
    igraph_matrix_int_init(&merges, 0, 0);

                              NULL /* no weights */,
                              4 /* steps */,
                              &merges, &modularity,
                              /* membership=*/ NULL);

    no_of_nodes = igraph_vcount(&g);
    for (i = 0; i < igraph_matrix_int_nrow(&merges); i++) {
        printf("%2.1" IGRAPH_PRId " + %2." IGRAPH_PRId " -> %2." IGRAPH_PRId " (modularity %4.2f)\n",
               MATRIX(merges, i, 0), MATRIX(merges, i, 1),
               no_of_nodes + i, VECTOR(modularity)[i]);



    return 0;

I am using the example code from GitHub - igraph/igraph-example: Example projects that demonstrate the usage of igraph, and replace one of the c file with my code, and following the instruction to compile and run my c code. Then I got this error. Does anyone has idea how to fix this problem? Thank you very much!

When I call this function, igraph_community_walktrap
I got this error:
error while loading shared libraries: ?: cannot open shared object file: No such file or directory\

This error seems like path setting problem, could anyone tell me how do you guys set up the igraph c library? How do you guys try to make the igraph c library works without this kind of problem?

If this is Windows, then try adding the directory containing igraph.dll to your PATH environment variable, or copying it to the location where your executable is. Does this fix the problem?

Thank you for your reply. I am using cygwin on windows 11, but the cygwin seems like UNIX environment, so should I add the igraph.dll to my executable location? BTW I can run our example code for no problem. just when I call igraph_community_walktrap, this error will happened.

It would be simplest to just try to copy igraph.dll to the same directory where runWalktrap.exe is. Does it work if you do this?

Do you know where can I find the igraph.dll?

When you installed igraph, according to the instructions in the tutorial, you specified an installation location. It will be in the bin subdirectory of that location.

Normally, that bin subdirectory should be added to the PATH. I expect that this is also the case with Cygwin.

However, simply copying igraph.dll to where your executable is might be sufficient.

Thank you for your instruction. But still can not find the igraph.dll.
I follow the install instruction as following steps:

  1. mkdir build && cd build
  2. cmake …
  3. cmake --build .

And it seems like successfully build. But I did not find the dll file.



folder is empty, and /usr/local/include/igraph has lots of header files.
My /usr/local/lib has the following files:

cmake libigraph.a pkgconfig

But none of them are igraph.dll.

It looks like you compiled igraph into a static library, not a shared library.

When you see this error message,

error while loading shared libraries: ?: cannot open shared object file:

is that really a question mark there? Or does it mention the name of a library? I assumed it was igraph.dll that was missing, but it seems it must be some other dependency.

At this point it’s quite difficult for me to give advice, not knowing the details of your system. You can use the Dependency Walker tool to find out what exactly runWalktrap.exe depends on, and then try to figure out why it can’t find those files. It might be a Cygwin-specific issue. Make sure you try to run the executable from a Cygwin terminal, if you compiled with Cygwin.

You can also try:

  • Compile igraph into a shared library
  • Do not use external dependencies; set it to use the vendored versions of libraries it depends on

You’ll find instructions on how to do this in the Installation section of the documentation

error while loading shared libraries: ?: cannot open shared object file: No such file or directory

It is a question mark, did not specific any name of libraries.

I installed the Dependency Walker tool. And I run the tool for runWalktrap.exe, and got the following info:

Error: At least one required implicit or forwarded dependency was not found.
Error: A circular dependency was detected.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

I can run our example code diameter.c for no problem, i can get the result without error. But when I run the walktrap example code, I will have the loading shared libraries error.

Hello, When I install the igraph-0.10.4 on linux, I follow the steps like these:

mkdir build && cd build
cmake …
cmake --build .
cmake --install .

On the cmake --install . step, I got an error.

CMake Error at src/cmake_install.cmake:61 (file):
file INSTALL cannot copy file
to “/usr/local/lib64/libigraph.a”: Success.
Call Stack (most recent call first):
cmake_install.cmake:52 (include)

When I google it, most of the answer suggest me to use sudo to slove this problem, but the question is I am working on the development server, I do not have the privilege to install it on the /usr/local path, do you have any idea about how to change the path from /usr/local/lib64 to another path?

Please read the tutorial carefully. The answer is there.

If you didn’t install igraph, then you did not follow the instructions in the tutorial, so it’s not surprising that things went wrong. A lot of time could have been saved if you mentioned this at the beginning.

Hi, I installed the igraph successfully by cygwin64 on windows 11.
But like I mentioned, I got an error which is error while loading shared libraries : ? : …
So I decided to switch to linux to install it and try to run it. And I got another error,

file INSTALL cannot copy file

Maybe I should open a new question to ask, actually these are spearate questions…

You need to specify an installation location where you have write permissions. See section 2.1 of the installation instructions.

For example,

mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/my_favourite_location

Then when you are using igraph from your own project, specify the same location as -DIGRAPH_PREFIX_PATH, see the tutorial.

On Unix-like systems, do not use ~ to refer to your home directory when setting CMake variables. Instead of ~/foo, write $HOME/foo, as in the above example.

1 Like

Thank you for your instruction. I fixed my problem, thank you so much. The solution is I should install it on my favourite location AND should not install it at the same level with build directory(this part I still not fully understand why but anyways it works!). Thank you again.