# Error installing libleidenalg package on a remote cluster. Probably really a question about cmake.

**URL:** <https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608>\
**Category:** Usage\
**Tags:** C\
**Created:** [6 July 2023 00:33 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608 "2023-07-06T00:33:51Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![markrbower1](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@markrbower1](https://igraph.discourse.group/u/markrbower1)\
**Post date:** [6 July 2023 00:33 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/1 "2023-07-06T00:33:52Z")

</div>

Because I’m on a remote cluster, I had to install igraph in my own directories:

```auto
${HOME}/igraph

```

Now that I am installing the libleidenalg package, I need to tell cmake where the igraph .h files are located, but I cannot figure out how to do that, so I get:

```auto
$ export PATH=$PATH:${HOME}/igraph/build
$ /ocean/projects/ibn210001p/mbower/cmake-3.23.0-linux-x86_64/bin/cmake ..
-- Version number from Git: 0.11.0-1-gd46d145
-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /jet/home/mbower/libleidenalg/build
$ /ocean/projects/ibn210001p/mbower/cmake-3.23.0-linux-x86_64/bin/cmake --build .
Consolidate compiler generated dependencies of target libleidenalg
[8%] Building CXX object src/CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o
In file included from /jet/home/mbower/libleidenalg/src/GraphHelper.cpp:1:
/jet/home/mbower/libleidenalg/include/GraphHelper.h:4:10: fatal error: igraph/igraph.h: No such file or directory
 #include <igraph/igraph.h>
          ^ ~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [src/CMakeFiles/libleidenalg.dir/build.make:76: src/CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:116: src/CMakeFiles/libleidenalg.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2
$

```

How do I tetll “cmake” where to look for .h files?

---

<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:** [6 July 2023 07:28 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/2 "2023-07-06T07:28:54Z")

</div>

From the [tutorial](https://igraph.org/c/html/latest/igraph-Tutorial.html#tut-lesson-1-compiling-with-cmake):

> 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.

---

<div class="post-metadata">

**Author:** ![markrbower1](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@markrbower1](https://igraph.discourse.group/u/markrbower1)\
**Post date:** [6 July 2023 16:09 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/3 "2023-07-06T16:09:03Z")

</div>

I have tried a number of things: different suggested options (“DCMAKE\_PREFIX\_PATH, igraph\_ROOT”, “prefix”, and even good old “I”) and I have tried several different levels of directories ({HOME}, {HOME}/igraph, ${HOME}/igraph/include), along with trying to set the path to “libigraph.a”. Also, I’ve tried “–DCMAKE…” and “-- DCMAKE …” with a space after the “–”, because no-space just gives an “unrecognized option” error. Clearly, I’m no “cmake” expert. 🙂

```auto
$ cmake --build . -- DCMAKE_PREFIX_PATH=/jet/home/mbower/igraph
[8%] Building CXX object src/CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o
In file included from /jet/home/mbower/libleidenalg/src/GraphHelper.cpp:1:
/jet/home/mbower/libleidenalg/include/GraphHelper.h:4:10: fatal error: igraph/igraph.h: No such file or directory
 #include <igraph/igraph.h>
          ^ ~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [src/CMakeFiles/libleidenalg.dir/build.make:76: src/CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:116: src/CMakeFiles/libleidenalg.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2
$
```

---

<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:** [6 July 2023 17:10 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/4 "2023-07-06T17:10:10Z")

</div>

Can you please provide the details on how you installed `igraph`?

Edit: you want to build a static library?

---

<div class="post-metadata">

**Author:** ![markrbower1](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@markrbower1](https://igraph.discourse.group/u/markrbower1)\
**Post date:** [6 July 2023 18:08 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/5 "2023-07-06T18:08:27Z")

</div>

```auto
cd ~
tar xvf igraph-0.10.4.tar
mv igraph-0.10.4 igraph

export CC=/usr/bin/gcc
export CXX=/usr/bin/g++

cd igraph
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/graph
cmake --build
cmake --install

```

This is a good check as to whether that is the correct sequence for installing igraph, too. 🙂

---

<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:** [6 July 2023 18:23 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/6 "2023-07-06T18:23:52Z")

</div>

> [@markrbower1](#):
>
> `cmake --build . -- DCMAKE_PREFIX_PATH=/jet/home/mbower/igraph`

This is not quite correct. There are two issues:

- The CMake option is `-D`, which must be followed by `VARIABLE=VALUE` syntax.
- The option must be given at configuration time, not build time.

So, something like:

```shell
mkdir build && cd build
cmake .. -DCMAKE_PREFIX_PATH=$HOME/igraph
cmake --build .

```

Let us know if this worked.

---

<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:** [6 July 2023 19:30 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/7 "2023-07-06T19:30:25Z")

</div>

You might find this general CMake guide useful:

[https://cmake.org/cmake/help/latest/guide/user-interaction/index.html](https://cmake.org/cmake/help/latest/guide/user-interaction/index.html)

It shows how to configure, compile and install packages that use CMake.

---

<div class="post-metadata">

**Author:** ![markrbower1](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@markrbower1](https://igraph.discourse.group/u/markrbower1)\
**Post date:** [6 July 2023 19:32 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/8 "2023-07-06T19:32:50Z")

</div>

Thank you for the cmake guide! I will take a look. As for the commands (below), I’m still getting the same error. I have run this so many times, should I do some type of “clean” first to clear out caches?

```auto
[mbower@v001 build]$ /ocean/projects/ibn210001p/mbower/cmake-3.23.0-linux-x86_64/bin/cmake .. -DCMAKE_PREFIX_PATH=$HOME/igraph
-- Version number from Git: 0.11.0-1-gd46d145
-- Configuring done
-- Generating done
-- Build files have been written to: /jet/home/mbower/libleidenalg/build
[mbower@v001 build]$ /ocean/projects/ibn210001p/mbower/cmake-3.23.0-linux-x86_64/bin/cmake --build .
Consolidate compiler generated dependencies of target libleidenalg
[8%] Building CXX object src/CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o
In file included from /jet/home/mbower/libleidenalg/src/GraphHelper.cpp:1:
/jet/home/mbower/libleidenalg/include/GraphHelper.h:4:10: fatal error: igraph/igraph.h: No such file or directory
 #include <igraph/igraph.h>
          ^ ~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [src/CMakeFiles/libleidenalg.dir/build.make:76: src/CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:116: src/CMakeFiles/libleidenalg.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2
[mbower@v001 build]$ 

```

---

<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:** [6 July 2023 20:23 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/9 "2023-07-06T20:23:20Z")

</div>

> [@markrbower1](#):
>
> `cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/graph`

Could you double check whether this might be a typo? That is, for `libleidenalg` you use `$HOME/igraph`, not `$HOME/graph`.

Perhaps you can do a directory listing to verify exactly what the location of `igraph.h` is?

---

<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:** [6 July 2023 21:22 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/10 "2023-07-06T21:22:55Z")

</div>

@vtraag, I believe `#include <igraph/igraph.h>` is not correct. The standard way is `#include <igraph.h>`. CMake generates a configuration for this method of inclusion. Can you double check this in libleidenalg? I did not look closely myself, at least not yet.

---

<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:** [6 July 2023 23:02 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/11 "2023-07-06T23:02:09Z")

</div>

I tested this on my system, and everything works fine. The `#include <igraph/igraph.h>` does not seem to be a problem, as the compiler appears to be passing `-isystem /Users/szhorvat/local/include/igraph -isystem /Users/szhorvat/local/include`. So both versions should work.

@markrbower1 Assuming you use the default Unix Makefiles generator, can you post the output of `VERBOSE=1 make` when building `libleidenalg`? Do a `make clean` first if you’ve already built the library once.

---

<div class="post-metadata">

**Author:** ![markrbower1](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@markrbower1](https://igraph.discourse.group/u/markrbower1)\
**Post date:** [6 July 2023 23:56 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/12 "2023-07-06T23:56:27Z")

</div>

I know that (at least on StackOverflow) you aren’t supposed to praise those who help, but many thanks to the “gurus” who are helping me!

@vtraag: I double-checked using $HOME/igraph, but got the same result as before.

@szhorvat: The “verbose” flag always intimidates me, but here goes:

```auto
[mbower@v001 build]$ /ocean/projects/ibn210001p/mbower/cmake-3.23.0-linux-x86_64/bin/cmake --build . --verbose
/ocean/projects/ibn210001p/mbower/cmake-3.23.0-linux-x86_64/bin/cmake -S/jet/home/mbower/libleidenalg -B/jet/home/mbower/libleidenalg/build --check-build-system CMakeFiles/Makefile.cmake 0
/ocean/projects/ibn210001p/mbower/cmake-3.23.0-linux-x86_64/bin/cmake -E cmake_progress_start /jet/home/mbower/libleidenalg/build/CMakeFiles /jet/home/mbower/libleidenalg/build//CMakeFiles/progress.marks
/usr/bin/gmake -f CMakeFiles/Makefile2 all
gmake[1]: Entering directory '/jet/home/mbower/libleidenalg/build'
/usr/bin/gmake -f src/CMakeFiles/libleidenalg.dir/build.make src/CMakeFiles/libleidenalg.dir/depend
gmake[2]: Entering directory '/jet/home/mbower/libleidenalg/build'
cd /jet/home/mbower/libleidenalg/build && /ocean/projects/ibn210001p/mbower/cmake-3.23.0-linux-x86_64/bin/cmake -E cmake_depends "Unix Makefiles" /jet/home/mbower/libleidenalg /jet/home/mbower/libleidenalg/src /jet/home/mbower/libleidenalg/build /jet/home/mbower/libleidenalg/build/src /jet/home/mbower/libleidenalg/build/src/CMakeFiles/libleidenalg.dir/DependInfo.cmake --color=
Dependencies file "src/CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o.d" is newer than depends file "/jet/home/mbower/libleidenalg/build/src/CMakeFiles/libleidenalg.dir/compiler_depend.internal".
Consolidate compiler generated dependencies of target libleidenalg
gmake[2]: Leaving directory '/jet/home/mbower/libleidenalg/build'
/usr/bin/gmake -f src/CMakeFiles/libleidenalg.dir/build.make src/CMakeFiles/libleidenalg.dir/build
gmake[2]: Entering directory '/jet/home/mbower/libleidenalg/build'
[8%] Building CXX object src/CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o
cd /jet/home/mbower/libleidenalg/build/src && /usr/bin/c++ -Dlibleidenalg_EXPORTS -I/jet/home/mbower/libleidenalg/build/include -I/jet/home/mbower/libleidenalg/include -isystem /jet/home/mbower/igraph/build/src/CMakeFiles/Export/include/igraph -isystem /jet/home/mbower/igraph/build/src/CMakeFiles/Export/include -fPIC -fvisibility=hidden -std=gnu++11 -MD -MT src/CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o -MF CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o.d -o CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o -c /jet/home/mbower/libleidenalg/src/GraphHelper.cpp
In file included from /jet/home/mbower/libleidenalg/src/GraphHelper.cpp:1:
/jet/home/mbower/libleidenalg/include/GraphHelper.h:4:10: fatal error: igraph/igraph.h: No such file or directory
 #include <igraph/igraph.h>
          ^ ~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [src/CMakeFiles/libleidenalg.dir/build.make:76: src/CMakeFiles/libleidenalg.dir/GraphHelper.cpp.o] Error 1
gmake[2]: Leaving directory '/jet/home/mbower/libleidenalg/build'
gmake[1]: *** [CMakeFiles/Makefile2:116: src/CMakeFiles/libleidenalg.dir/all] Error 2
gmake[1]: Leaving directory '/jet/home/mbower/libleidenalg/build'
gmake: *** [Makefile:156: all] Error 2
[mbower@v001 build]$ 

```

---

<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:** [7 July 2023 07:31 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/13 "2023-07-07T07:31:39Z")

</div>

You need to install packages into a different location than where you extracted their sources!

---

<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:** [7 July 2023 08:20 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/14 "2023-07-07T08:20:46Z")

</div>

Just to make sure to get everything right, here are all the steps to build `igraph` and `libleidenalg`:

```bash
# Fetch latest version of igraph
curl -LO https://github.com/igraph/igraph/releases/download/0.10.5/igraph-0.10.5.tar.gz
tar xvf igraph-0.10.5.tar.gz

# Create separate build and install directories
mkdir build
mkdir install

# Build igraph
cd build
mkdir igraph/
cd igraph
cmake ../../igraph-0.10.5 -DCMAKE_INSTALL_PREFIX=../../install -DBUILD_SHARED_LIBS=OFF
cmake --build . --target install
cd ../..

# Fetch latest version of libleidenalg
curl -Lo libleidenalg-0.11.0.tar.gz https://github.com/vtraag/libleidenalg/archive/refs/tags/0.11.0.tar.gz
tar xvf libleidenalg-0.11.0.tar.gz

# Build libleidenalg
cd build
mkdir libleidenalg/
cd libleidenalg
cmake ../../libleidenalg-0.11.0 -DCMAKE_INSTALL_PREFIX=../../install -DCMAKE_PREFIX_PATH=../../install -DBUILD_SHARED_LIBS=OFF
cmake --build . --target install
cd ../..

```

Starting from a directory, i.e. your home directory `/jet/home/mbower/`, this downloads both tar balls from `igraph` and `libleidenalg` in your home directory. It builds it in the build directories `build/igraph` and `build/libleidenalg` and installs them in the `install` directory. Within the `install` directory, there is then the `lib`, `include` and `share` directory.

I’m not sure how you plan to work with these libraries yourself, but in principle, you could just point to the `install/include` and `install/lib` directories to compile/link.

Of course, you can change around the paths as needed by you locally. But perhaps you could just run all these lines exactly as they are, to make sure that everything at least works as intended. If that works, then you can go change paths.

Note that by default `igraph` builds a static library, while `libleidenalg` builds a shared library by default, so you have to explicitly specify that you want a static library.

---

<div class="post-metadata">

**Author:** ![markrbower1](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@markrbower1](https://igraph.discourse.group/u/markrbower1)\
**Post date:** [8 July 2023 15:19 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/15 "2023-07-08T15:19:26Z")

</div>

@szhorvat Thank you for that info! That is incredibly helpful!

@vtraag Your script worked perfectly! As a user, that would be super helpful to have available in the README. It’s also nice to serve as a template for downloading and installing other packages.

Many thanks to both of you!

---

<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:** [8 July 2023 17:52 UTC](https://igraph.discourse.group/t/error-installing-libleidenalg-package-on-a-remote-cluster-probably-really-a-question-about-cmake/1608/16 "2023-07-08T17:52:13Z")

</div>

Great to hear it worked! I’ll see if I can update the README. In the meantime, you could accept the post as an answer so that others see the solution more quickly.
