Skip to content

Building libgit2 on Windows

arrbee edited this page Feb 23, 2013 · 16 revisions

Building libgit2 on Windows

All developers are required to submit patches that work not only on Mac and Linux but also on Windows. In case you do not have a Windows machine available please at least use a VirtualBox VM. All you need to do is install Virtual Box and use the following script to install Windows automatically. The Ballmer Demands It™.

Attack of the Ballmer

Getting a compiler, CMake and libgit2

  1. libgit2 officially supports two compilers on Windows, Microsoft Visual Studio and MinGW GCC.
  2. Download and install the latest CMake
  3. Download and install the latest Python
  4. Grab the source for libgit2 via GitHub (Here's how you do that), alternatively you download it directly.

Note: older versions of CMake may not support the latest Python. If you encounter a problem, please try upgrading. Thanks!

Building using Visual Studio

  1. Open the VS2010 Command Prompt (not a regular cmd prompt or the Windows SDK one!)
  2. cd into the libgit2 directory
  3. mkdir build && cd build
  4. cmake .. or cmake-gui ..
  5. cmake --build .
  6. ctest -V
  7. cmake --build . --target install

Creating a solution file

If you'd like to create a solution file, then just change the fourth step to be

cmake .. -G"Visual Studio X"

where 'X' is your version of Visual Studio (i.e. '2010', '2008'). Running cmake by itself will tell you which targets it supports. You can also select it in the CMake GUI.

Building using MinGW

  1. Open regular command line. Start, type cmd.exe
  2. cd into the libgit2 directory
  3. mkdir build && cd build
  4. cmake .. -G"MinGW Makefiles" or cmake-gui .. and make sure you select MinGW Compiler
  5. cmake --build . or cmake --build . -- -j for parallel build
  6. ctest -V
  7. cmake --build . --target install

Notes

You can change the build settings on step 4 using cmake-gui or from commandline by defining CMake attributes. For example to change the install destination use:

cmake . -DCMAKE_INSTALL_PREFIX=C:\libgit2