How to use libgit2 from a native C++ application on Windows? (Microsoft VC++)

和自甴很熟 提交于 2019-11-29 17:46:59

This strongly suggests a calling convention mismatch to me. libgit2 uses __stdcall by default, for a number of reasons, while Visual Studio defaults to creating projects that use the __cdecl calling convention. While your program can use either calling convention and successfully call libgit2 using a different one, the easiest solution is probably just to use the same calling convention for both.

When you configure libgit2, you can turn off the STDCALL flag, which will cause it to emit a library built with __cdecl calling conventions:

cmake %PATH_TO_LIBGIT2_SOURCE% -DTHREADSAFE=ON -DSTDCALL=OFF
cmake --build .

It's a little surprising if you generated the project from CMake, bit it could be that you're not linking to libgit2.lib. Make sure you have git2.dll in Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!