Fatal error: glpk.h: No such file or directory during the installation #1273

Hi,
I’m trying to install igraph package in R 4.3.1 inside Centos/Red Hat 8 through install.packages(‘igraph’) but I have encountered this error:

vendor/cigraph/src/internal/glpk_support.h:39:10: fatal error: glpk.h: No such file or directory
39 | #include <glpk.h>
| ^~~~~~~~
compilation terminated.
make: *** [/opt/R/4.3.1/lib/R/etc/Makeconf:191: vendor/cigraph/src/community/optimal_modularity.o] Error 1
ERROR: compilation failed for package ‘igraph’
`

The glpk was installed and, before the attempt of igraph installation, I also loaded the corresponding environment module through module load glpk. I think that the compiler doesn’t see the include folder of the glpk package that is present in the system. So I have tried to insert inside the C_INCLUDE_PATH the path to the include folder of glpk using this command:

Sys.setenv(C_INCLUDE_PATH="/share/apps/spack/latest-2024-01-17/linux-centos8-skylake_avx512/gcc-8.4.1/glpk-4.65-p4yflusvdbtjwtt5mhqkfobr5nxubp3f/include")

But also in this case I encountered an error that is reported below:

ld cannot find -lglpk

To solve this last error, I have tried to load the corresponding libglpk.so library and retry to launch install.packages(‘igraph’) but it gives the same error.

Could you have any suggestions to solve the issue?

Thank you in advance,
Greetings

Jessica

Try creating the file ~/.R/Makevars and enter the relevant compiler flags. Add at least the following two lines to this file:

CPPFLAGS=-I/path/to/include/directory
LDFLAGS=-L/path/to/library/directory

Let me know if this worked. If it did not, be sure to post a few of the output lines just prior to the error message you already posted above, so we can see the flags that were passed to the compiler.

1 Like

Ok, thank you. I will give you a feedback.

Now, it works.

Thank you very very much :slight_smile:

Have a nice day,
Jessica

1 Like