首先,我只是 CMake 魔法的新手。我只想以 CMake 方式(FindLibgit2.cmake)将 libgit2 链接到我的简单 C 程序。正如我从cmake 文档中了解的那样,我的 CMakeLists.txt 应该如下所示:
project(libgit2test)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
# This variables should be setting up externally, i know - i show them just for example
set (LIBGIT2_LIBRARIES "<path to directory with git2.lib and git2.dll")
set (LIBGIT2_INCLUDE_DIR "<path to libgit2/include>")
find_package(Libgit2 REQUIRED)
include_directories(${LIBGIT2_INCLUDE_DIR})
set(LIBS ${LIBS} ${LIBGIT2_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${LIBS})
在我的简单程序中,我只调用了几个简单的libgit2
函数并得到这个:
WARNING: Target "libgit2test" requests linking to directory "<libgit2 build directory>". Targets may link only to libraries. CMake is dropping the item.
我认为问题出在此处:target_link_libraries(${PROJECT_NAME} {$LIBS})
我尝试将其更改为git2
,但我只是得到了can not open file
。我做错了什么?
PS 我正在使用 Visual Studio 2010 编译器、Qt Creator 创建 CMake 项目,并libgit2
使用 CMake 成功构建。