14 October 2013

Statically Compiling Git

If you don't have access to a C compiler, or have the ability to install an RPM on a machine, but you still want to use git, you need to create yourself a statically linked binary on another machine and copy it over.

The process to do this is supposed to be pretty easy, but there are a host of libraries that you need to install. I already had a working Centos 6.4 VM, with gcc, openssl, curl etc installed. Basically all the dependencies required to compile git with the usual commands:

$ make
$ make install

Before attempting a static build, you will also need to install at least the following with yum:

  • glibc-static
  • zlib-static
  • libssh2-devel
  • openldap-devel
  • curl-devel

Then, you can create a static build in ~/bin using the following commands:

# Create the configure executable
$ make configure
# Configure the build
$ ./configure --prefix=/home/sodonnel/bin CFLAGS="${CFLAGS} `pkg-config --static --libs libcurl`"
# make and install as usual
$ make
$ make install

Another guide suggested using the following for the configure step:

$ ./configure --prefix=/home/sodonnel/bin CFLAGS="${CFLAGS} -static"

I tried this, but I was not able to clone a repo over https so I tried the version above that was mentioned in the comments.

If all goes well, you should have a working git in /home/sodonnel/bin/bin/git.

To move this onto another machine, simple tar up /home/sodonnel/bin and then untar at the destination.

If you get problems during the configure stage, look at config.log - it will probably give an error indicating a library is missing. Install it and try again.

You also need to make sure you build on a machine with the same kernel version, OS version, architecture (32 or 64 bit) as the host.

After following these steps and transferring the build to my target machine, I still get one warning I cannot resolve. Each time I run a git command, it prints the following:

git: /lib64/libz.so.1: no version information available (required by git) static 

The commands all seem to work OK despite that error message, but if anyone has any ideas on how to make this message go away I would be very grateful!

blog comments powered by Disqus