# How to create dynamic lib of \`libgit2\` using CMake

**URL:** <https://discourse.cmake.org/t/how-to-create-dynamic-lib-of-libgit2-using-cmake/3305>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [May 12, 2021, 5:35pm UTC](https://discourse.cmake.org/t/how-to-create-dynamic-lib-of-libgit2-using-cmake/3305 "2021-05-12T17:35:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nivekithan](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nivekithan/32/1437_2.png) [@nivekithan](https://discourse.cmake.org/u/nivekithan)\
**Post date:** [May 12, 2021, 5:35pm UTC](https://discourse.cmake.org/t/how-to-create-dynamic-lib-of-libgit2-using-cmake/3305/1 "2021-05-12T17:35:04Z")

</div>

First of all I have no experience with `c` and its ecosystem so the questions I ask could be too basic.

I am trying to create `dart` bindings for [libgit2](https://github.com/libgit2/libgit2). To do that I have to create dynamic library. I followed the steps from the Official documentation (dart .dev/guides/libraries/c-interop)

discourse .cmake .org is not allowing to post more than two links, thats why above text is not link

This repo [nivekithan/git2dart](https://github.com/nivekithan/git2dart) contains my effort on creating dynamic library.

Before posting here I have also asked the same question in stack-overflow (stackoverflow .com/questions/67505823/cmake-is-not-making-makefile?noredirect=1#67507666)

I will repeat the content in `stackoverflow` here also

I am trying to create dynamic library in windows. I followed the instruction in (github .com/dart-lang/samples/tree/master/ffi).

This is my `CMakelists.txt`

```auto
cmake_minimum_required(VERSION 3.20.2 FATAL_ERROR)
project(libgit VERSION 1.0.0 LANGUAGES C)
add_library(libgit SHARED git2.h)

set_target_properties(libgit PROPERTIES
    PUBLIC_HEADER git2dart.h
    VERSION {PROJECT_VERSION}
    SOVERSION 1
    LINKER_LANGUAGE C
    OUTPUT_NAME "git2dart"
)

```

You can clone the repo using in `gh repo clone nivekithan/git2dart`

You will find the `CMakeFiles.txt` in the directory `libgit2`.

If I were run `cmake .` from this directory then I would get this message

```auto
 Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.21376.
-- The C compiler identification is MSVC 19.28.29914.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/nivek/Documents/work/git2dart/libgit2

```

But then If I were to run `make` I would get this message

```auto
make: *** No targets specified and no makefile found. Stop.

```

Thanks for the help

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [May 12, 2021, 5:39pm UTC](https://discourse.cmake.org/t/how-to-create-dynamic-lib-of-libgit2-using-cmake/3305/2 "2021-05-12T17:39:51Z")

</div>

Right now your `libgit` only has a single source: `git2.h`. CMake recognizes this as a header file and thus doesn’t compile it. You need to add additional `.c`/`.cpp`/`.cxx`/whatever sources.

---

<div class="post-metadata">

**Author:** ![nivekithan](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nivekithan/32/1437_2.png) [@nivekithan](https://discourse.cmake.org/u/nivekithan)\
**Post date:** [May 12, 2021, 5:43pm UTC](https://discourse.cmake.org/t/how-to-create-dynamic-lib-of-libgit2-using-cmake/3305/3 "2021-05-12T17:43:23Z")

</div>

I copied the code from `include` directory from [libgit2](https://github.com/libgit2/libgit2) . It only contains `.h` files. The `.c` files are in directory `src` if I were to copy those then what should I mention in `add_libary(libgit SHARED <????>)` there is no `git2.c` file

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [May 12, 2021, 5:45pm UTC](https://discourse.cmake.org/t/how-to-create-dynamic-lib-of-libgit2-using-cmake/3305/4 "2021-05-12T17:45:17Z")

</div>

Let me back up a second… are you trying to build all of `libgit2` from source, and add Dart bindings on top of that, or are you trying to use a pre-built version of `libgit2` and add Dart bindings to that?

---

<div class="post-metadata">

**Author:** ![nivekithan](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nivekithan/32/1437_2.png) [@nivekithan](https://discourse.cmake.org/u/nivekithan)\
**Post date:** [May 12, 2021, 5:48pm UTC](https://discourse.cmake.org/t/how-to-create-dynamic-lib-of-libgit2-using-cmake/3305/5 "2021-05-12T17:48:33Z")

</div>

I dont know. As I said I am not entirely familiar with c ecosystem and this is my first building a binding library. So I am not entirely sure.

---

<div class="post-metadata">

**Author:** ![nivekithan](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nivekithan/32/1437_2.png) [@nivekithan](https://discourse.cmake.org/u/nivekithan)\
**Post date:** [May 12, 2021, 5:49pm UTC](https://discourse.cmake.org/t/how-to-create-dynamic-lib-of-libgit2-using-cmake/3305/6 "2021-05-12T17:49:20Z")

</div>

maybe this could be helpful [C interop using dart:ffi | Dart](https://dart.dev/guides/libraries/c-interop), I am not sure though
