Связывание с libgit2 в Clion не работает

Я нахожу, что трудно запустить что-либо с помощью libgit2 API в Clion. У меня есть установить все необходимое, используя Homebrew. с помощью этого редактирования перед

  args = std_cmake_args
  ...
  args << "-DBUILD_SHARED_LIBS=OFF"

#include <git2.h> работает хорошо, но я не могу, кажется, запустить его.

я попробовал несколько простых примеров, похоже, не работает, поэтому я решил взять пример libgit2 отсюда, чтобы посмотреть, будет ли он работать, но нет хороших новостей
я получаю следующие ошибки

/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/addo/ClionProjects/Libgit2Training/cmake-build-debug --target Libgit2Training -- -j 4 [ 50%] Building C object CMakeFiles/Libgit2Training.dir/main.c.o [100%] Linking C executable Libgit2Training Undefined symbols for architecture i386:   "_git_blob_lookup", referenced from:
      _blob_parsing in main.c.o   "_git_blob_rawcontent", referenced from:
      _blob_parsing in main.c.o   "_git_blob_rawsize", referenced from:
      _blob_parsing in main.c.o   "_git_commit_author", referenced from:
      _commit_parsing in main.c.o
      _revwalking in main.c.o   "_git_commit_committer", referenced from:
      _commit_parsing in main.c.o   "_git_commit_create_v", referenced from:
      _commit_writing in main.c.o   "_git_commit_free", referenced from:
      _commit_parsing in main.c.o
      _tag_parsing in main.c.o
      _revwalking in main.c.o   "_git_commit_id", referenced from:
      _commit_parsing in main.c.o   "_git_commit_lookup", referenced from:
      _commit_writing in main.c.o
      _commit_parsing in main.c.o
      _revwalking in main.c.o   "_git_commit_message", referenced from:
      _commit_parsing in main.c.o
      _revwalking in main.c.o   "_git_commit_parent", referenced from:
      _commit_parsing in main.c.o   "_git_commit_parentcount", referenced from:
      _commit_parsing in main.c.o   "_git_commit_time", referenced from:
      _commit_parsing in main.c.o   "_git_config_get_int32", referenced from:
      _config_files in main.c.o   "_git_config_get_string", referenced from:
      _config_files in main.c.o   "_git_config_open_ondisk", referenced from:
      _config_files in main.c.o   "_git_index_entrycount", referenced from:
      _index_walking in main.c.o   "_git_index_free", referenced from:
      _index_walking in main.c.o   "_git_index_get_byindex", referenced from:
      _index_walking in main.c.o   "_git_libgit2_init", referenced from:
      _main in main.c.o   "_git_libgit2_shutdown", referenced from:
      _main in main.c.o   "_git_object_free", referenced from:
      _tree_parsing in main.c.o   "_git_object_type2string", referenced from:
      _object_database in main.c.o
      _tag_parsing in main.c.o   "_git_odb_object_data", referenced from:
      _object_database in main.c.o   "_git_odb_object_free", referenced from:
      _object_database in main.c.o   "_git_odb_object_size", referenced from:
      _object_database in main.c.o   "_git_odb_object_type", referenced from:
      _object_database in main.c.o   "_git_odb_read", referenced from:
      _object_database in main.c.o   "_git_odb_write", referenced from:
      _object_database in main.c.o   "_git_oid_fmt", referenced from:
      _oid_parsing in main.c.o
      _object_database in main.c.o
      _commit_writing in main.c.o
      _commit_parsing in main.c.o
      _reference_listing in main.c.o   "_git_oid_fromstr", referenced from:
      _oid_parsing in main.c.o
      _commit_writing in main.c.o
      _commit_parsing in main.c.o
      _tag_parsing in main.c.o
      _tree_parsing in main.c.o
      _blob_parsing in main.c.o
      _revwalking in main.c.o
      ...   "_git_reference_list", referenced from:
      _reference_listing in main.c.o   "_git_reference_lookup", referenced from:
      _reference_listing in main.c.o   "_git_reference_symbolic_target", referenced from:
      _reference_listing in main.c.o   "_git_reference_target", referenced from:
      _reference_listing in main.c.o   "_git_reference_type", referenced from:
      _reference_listing in main.c.o   "_git_repository_free", referenced from:
      _main in main.c.o   "_git_repository_index", referenced from:
      _index_walking in main.c.o   "_git_repository_odb", referenced from:
      _object_database in main.c.o   "_git_repository_open", referenced from:
      _main in main.c.o   "_git_revwalk_free", referenced from:
      _revwalking in main.c.o   "_git_revwalk_new", referenced from:
      _revwalking in main.c.o   "_git_revwalk_next", referenced from:
      _revwalking in main.c.o   "_git_revwalk_push", referenced from:
      _revwalking in main.c.o   "_git_revwalk_sorting", referenced from:
      _revwalking in main.c.o   "_git_signature_new", referenced from:
      _commit_writing in main.c.o   "_git_strarray_free", referenced from:
      _reference_listing in main.c.o   "_git_tag_lookup", referenced from:
      _tag_parsing in main.c.o   "_git_tag_message", referenced from:
      _tag_parsing in main.c.o   "_git_tag_name", referenced from:
      _tag_parsing in main.c.o   "_git_tag_target", referenced from:
      _tag_parsing in main.c.o   "_git_tag_target_type", referenced from:
      _tag_parsing in main.c.o   "_git_tree_entry_byindex", referenced from:
      _tree_parsing in main.c.o   "_git_tree_entry_byname", referenced from:
      _tree_parsing in main.c.o   "_git_tree_entry_name", referenced from:
      _tree_parsing in main.c.o   "_git_tree_entry_to_object", referenced from:
      _tree_parsing in main.c.o   "_git_tree_entrycount", referenced from:
      _tree_parsing in main.c.o   "_git_tree_lookup", referenced from:
      _commit_writing in main.c.o
      _tree_parsing in main.c.o   "_giterr_last", referenced from:
      _check_error in main.c.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[3]: *** [Libgit2Training] Error 1 make[2]: *** [CMakeFiles/Libgit2Training.dir/all] Error 2 make[1]: *** [CMakeFiles/Libgit2Training.dir/rule] Error 2 make: *** [Libgit2Training] Error 2

это мой CmakeList.txt в Клионе

cmake_minimum_required(VERSION 3.6)
project(Libgit2Training)

#set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c11 ")



set(SOURCE_FILES main.c)
add_executable(Libgit2Training ${SOURCE_FILES})

я попытался помочь на libgit2странице и изменил свой CmakeList.txtнабор() на это

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c11
        CFLAGS += -I/usr/local/Cellar/libgit2/include
        LDFLAGS += -L/usr/local/Cellar/libgit2/binaries
        LIBRARIES += -lgit2  ")

и я получил следующие ошибки: минимизировать я вижу

/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/addo/ClionProjects/Libgit2Training/cmake-build-debug --target Libgit2Training -- -j 4
[ 50%] Building C object CMakeFiles/Libgit2Training.dir/main.c.o
[100%] Linking C executable Libgit2Training
clang: error: no input files
make[3]: *** [Libgit2Training] Error 1
make[2]: *** [CMakeFiles/Libgit2Training.dir/all] Error 2
make[1]: *** [CMakeFiles/Libgit2Training.dir/rule] Error 2
make: *** [Libgit2Training] Error 2

seemed not to parse in a .c file.

Я новичок в libgit2

Я просто пытаюсь познакомиться и учиться на этом, но не может, кажется, работать, как любой обычный API, который я знаю. Вся помощь будет оценена.

С Новым Годом!!!

1 ответ

  1. Я решил этот вопрос сейчас. Благодаря @CarlosMartínNieto, я искал не то место. Я изменил CMakefileList на это:

    cmake_minimum_required(VERSION 3.6)
    project(Libgit2Training)
    
    #set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c11 -L/opt/local/lib -lgit2 -lssh2")
    
    /opt/local/lib # for macports
    
    set(SOURCE_FILES main.c)
    add_executable(Libgit2Training ${SOURCE_FILES})
    

    I was still getting built for x86_64 architecture being linked (i386) error so i changed the build option in the Clionpreference to this

    -D "CMAKE_OSX_ARCHITECTURES:STRING=x86_64"
    

    И теперь все работает. Я думаю, что теперь мне будет веселее с libgit2 API. Спасибо.