Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Can't use libgit2 as a CMake subproject together with googletest

Aperta
#7,162 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
c, cmake
Ambito
build-system

Direzione di ricerca

Riproduci le due configurazioni FetchContent con CMake 3.28.3, quindi esamina cmake/FindStatNsec.cmake e le voci di CMakeConfigureLog.yaml relative al controllo che fallisce. Il lavoro è completato quando libgit2 viene configurato e compilato correttamente aggiungendo prima googletest, senza l’errore errato del controllo -std=c90.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I'm using CMake 3.28.3 and GCC 13.3.0 on Ubuntu 24.04 on amd64. I'm trying to use libgit2 1.9.1 as a subproject of my own project.

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.28.3)

project(myProject VERSION 0.0.1 LANGUAGES C)

include(FetchContent)

FetchContent_Declare(
  libgit2
  GIT_REPOSITORY https://github.com/libgit2/libgit2.git
  GIT_TAG        0060d9cf5666f015b1067129bd874c6cc4c9c7ac  # v1.9.1
)
FetchContent_MakeAvailable(libgit2)

add_library(lib)
target_sources(lib PRIVATE lib.c)
target_link_libraries(lib PRIVATE libgit2)

When I run cmake -B build in my project's directory, cmake/FindStatNsec.cmake from libgit2 will call

check_struct_has_member("struct stat" st_mtim "sys/types.h;sys/stat.h"
        HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C)

CMake will create a C file that references struct stat's st_mtim member variable and compile it with no special compiler flags. On my system, this is successful:

        /usr/bin/cc -DHAVE_STRUCT_STAT_ST_MTIM   -o CMakeFiles/cmTC_2a383.dir/src.c.o -c /app/build/CMakeFiles/CMakeScratch/TryCompile-3aEPgD/src.c

(taken from build/CMakeFiles/CMakeConfigureLog.yaml)

However when I add googletest before libgit2 like this:

cmake_minimum_required(VERSION 3.28.3)

project(myProject VERSION 0.0.1 LANGUAGES C)

include(FetchContent)

FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG        52eb8108c5bdec04579160ae17225d66034bd723  # v1.17.0
)
FetchContent_MakeAvailable(googletest)

FetchContent_Declare(
  libgit2
  GIT_REPOSITORY https://github.com/libgit2/libgit2.git
  GIT_TAG        0060d9cf5666f015b1067129bd874c6cc4c9c7ac  # v1.9.1
)
FetchContent_MakeAvailable(libgit2)

add_library(lib)
target_sources(lib PRIVATE lib.c)
target_link_libraries(lib PRIVATE libgit2)

then the check for st_mtim will fail because the compiler will be called with -std=c90:

        /usr/bin/cc -DHAVE_STRUCT_STAT_ST_MTIM  -std=c90 -o CMakeFiles/cmTC_99f3b.dir/src.c.o -c /app/build/CMakeFiles/CMakeScratch/TryCompile-df2ogP/src.c
        /app/build/CMakeFiles/CMakeScratch/TryCompile-df2ogP/src.c: In function 'main':
        /app/build/CMakeFiles/CMakeScratch/TryCompile-df2ogP/src.c:7:36: error: 'struct stat' has no member named 'st_mtim'; did you mean 'st_mtime'?
            7 |   (void)sizeof(((struct stat *)0)->st_mtim);
              |                                    ^~~~~~~
              |                                    st_mtime

Building my project with cmake --build build will fail with

[  1%] Building C object _deps/libgit2-build/src/libgit2/CMakeFiles/libgit2.dir/annotated_commit.c.o
In file included from /app/build/_deps/libgit2-src/src/util/posix.h:157,
                 from /app/build/_deps/libgit2-src/src/util/git2_util.h:111,
                 from /app/build/_deps/libgit2-src/src/libgit2/common.h:10,
                 from /app/build/_deps/libgit2-src/src/libgit2/annotated_commit.h:10,
                 from /app/build/_deps/libgit2-src/src/libgit2/annotated_commit.c:8:
/app/build/_deps/libgit2-src/src/util/unix/posix.h:35:3: error: #error GIT_USE_NSEC defined but unknown struct stat nanosecond type
   35 | # error GIT_USE_NSEC defined but unknown struct stat nanosecond type
      |   ^~~~~
cc1: note: unrecognized command-line option '-Wno-documentation-deprecated-sync' may have been intended to silence earlier diagnostics
gmake[2]: *** [_deps/libgit2-build/src/libgit2/CMakeFiles/libgit2.dir/build.make:76: _deps/libgit2-build/src/libgit2/CMakeFiles/libgit2.dir/annotated_commit.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:642: _deps/libgit2-build/src/libgit2/CMakeFiles/libgit2.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

I haven't looked further into this yet. It might as well be a googletest bug and not a libgit2 bug.

Lingua principale
C
Stelle
10.6k
Fork
2.7k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di libgit2/libgit2

Tutte le issue di libgit2/libgit2

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.