Search code examples
libgit2

libgit2 is not building in release mode on windows


I am trying to build libgit2 in release mode on Windows 10 x64.

In my libgit2 directory, I run the following:

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .

It still builds in debug mode, as far as I can tell. At least when I link it into a Visual Studio project it fails on debug assertions.

I have also tried

cmake -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Release ..

to no avail.

I even tried to get it working by including all of the .vxcproj files in my solution and building them all in release mode manually. No luck yet.

Is it supposed to be as simple as passing in the -DCMAKE_BUILD_TYPE=Release flag or am I missing something?

All I am really trying to do is keep the git2.dll from exploding on debug asserts when I run it. At least I think that is what is happening.

Here is the code I am trying to run from a Visual Studio 2013 project, where I linked in the git2.lib and referenced the git2.dll as mentioned here

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    const char *path = "C:/Dev/testing/brokenmerge";
    git_repository *repo = NULL;

    git_repository_open(&repo, path);

    printf("Opened repo: '%s'\n", path);

    git_repository_free(repo);

    return 0;
}

where stdafx.h includes <git2.h>

I get the following assertion error in git_repository_open:

Assertion failed!

Program: C:\Dev\testing\libgit2tests\Debug\git2.dll
File: C:\Dev\libgit2\src\global.c
Line: 202

Expression: git_atomic_get(&git__n_inits) > 0

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts

So unless I linked to git2 incorrectly or I am doing something else wrong I have no idea how to proceed.

Thanks!


Solution

  • You need to call git_libgit2_init before calling any other libgit2 functions. This sets up the global state that the library needs.