最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Couldn't install R package 'devtools' as 'Configuration failed to find libgit2 library'

matteradmin2PV0评论

I was using remote server as a non-root user and trying to do some single cell analysis. When I installed R package 'devtools' simply using install.packages("devtools") I got dozens of error info. At first I got

Error in curl::curl_download(".sh", : 
SSL connect error [r-lib.github.io]: Recv failure: Connection reset by peer

Then I got

Found pkg-config cflags and libs!
Using PKG_CFLAGS=
Using PKG_LIBS=-L/usr/local/lib64 -lgit2

Both of them led to

<stdin>:1:10: fatal error: git2.h: No such file or directory
compilation terminated.

I was using remote server as a non-root user and trying to do some single cell analysis. When I installed R package 'devtools' simply using install.packages("devtools") I got dozens of error info. At first I got

Error in curl::curl_download("https://r-lib.github.io/gert/get-libgit2-linux.sh", : 
SSL connect error [r-lib.github.io]: Recv failure: Connection reset by peer

Then I got

Found pkg-config cflags and libs!
Using PKG_CFLAGS=
Using PKG_LIBS=-L/usr/local/lib64 -lgit2

Both of them led to

<stdin>:1:10: fatal error: git2.h: No such file or directory
compilation terminated.
Share Improve this question edited Nov 19, 2024 at 2:13 Nicolas Fong asked Nov 18, 2024 at 10:40 Nicolas FongNicolas Fong 113 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

I finally installed it and here is what I've tried

At first, I got

* installing *source* package ‘gert’ ...
** package ‘gert’ successfully unpacked and MD5 sums checked
** using staged installation
Error in curl::curl_download("https://r-lib.github.io/gert/get-libgit2-linux.sh",  : 
  SSL connect error [r-lib.github.io]: Recv failure: Connection reset by peer
Calls: <Anonymous> -> raise_libcurl_error
Execution halted
Using PKG_CFLAGS=
Using PKG_LIBS=-lgit2
----------------------------- ANTICONF -------------------------------
Configuration failed to find libgit2 library. Try installing:
 * brew: libgit2 (MacOS)
 * deb: libgit2-dev (Debian, Ubuntu, etc)
 * rpm: libgit2-devel (Fedora, CentOS, RHEL)
If libgit2 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libgit2.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
-------------------------- [ERROR MESSAGE] ---------------------------
<stdin>:1:10: fatal error: git2.h: No such file or directory
compilation terminated.

I noticed the message If libgit2 is already installed, check that 'pkg-config' is in your PATH and PKG_CONFIG_PATH contains a libgit2.pc file. So I searched my own dir but there wasn't the ‘libgit2.pc’ file.

Then I googled libgit2 and found its github releases in https://github/libgit2/libgit2/releases. I downloaded the latest version and built it following the installation guide. After that I got libgit2.so and libgit2.pc. Then I assigned the pkgconfig dir with export PKG_CONFIG_PATH=/home/fangyy/miniconda3/envs/r4.4.1/lib/pkgconfig/ and copied libgit2.pc to it, as well as copy .so files to specified lib dir (as I was non-root user). After that, I runed the 'install.packages()' and got sligthly different error info:

* installing *source* package ‘gert’ ...
** package ‘gert’ successfully unpacked and MD5 sums checked
** using staged installation
Found pkg-config cflags and libs!
Using PKG_CFLAGS=
Using PKG_LIBS=-L/usr/local/lib64 -lgit2 
----------------------------- ANTICONF -------------------------------
Configuration failed to find libgit2 library. Try installing:
 * brew: libgit2 (MacOS)
 * deb: libgit2-dev (Debian, Ubuntu, etc)
 * rpm: libgit2-devel (Fedora, CentOS, RHEL)
If libgit2 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libgit2.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
-------------------------- [ERROR MESSAGE] ---------------------------
<stdin>:1:10: fatal error: git2.h: No such file or directory
compilation terminated.

This time, pkg-config was found, which means the ’libgit2.pc' file worked I guess. But the using PKG_LIBS wasn't the lib dir I assigned. The words If pkg-config is unavailable you can set INCLUDE_DIR and LIB_DIR manually via: R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...' reminded me. I realized that I could set the lib path in install.packges(). So I tried:

install.packages("gert", configure.vars='INCLUDE_DIR=/home/fangyy/software/libgit2-1.8.4/include LIB_DIR=/home/fangyy/miniconda3/envs/r4.4.1/lib/')

Eventually, gert was installed and so was devtools

This experience teached me a lot. The most important thing I think is when a dependency library file wasn't in the /usr/lib, build it ourselves and assign the path we built lib file when installing may be an effective choice.

Post a comment

comment list (0)

  1. No comments so far