我一直在为 Qt 中的一个错误而苦苦挣扎:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol _git_repository_open referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)
这显然是一个链接错误,但我无法弄清楚是什么原因造成的。这都是在 Windows 上编译的,我的目标库是 libgit2。
我使用 MVSC2010(我也用于我的 Qt 构建)编译了 libgit2,然后将外部库添加到我的 Qt 项目中。包含被确认没有问题,但库没有正确链接。由于 libgit2 是一个 C 库,我尝试将该库包含在 extern 块中(也没有 exern 块)但无济于事:
extern "C" {
#include <git2.h>
}
此外,该函数位于lib 文件中:
dumpbin /EXPORTS git2.lib
...
_git_repository_open@8
...
引发错误的相关行(第一行如果单独工作,因为它是在 git 标头中定义的,但第二行在链接时失败):
git_repository *repo;
git_repository_open(&repo, "/opt/libgit2-test/.git");
相关的 qt.pro 文件行:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libgit2/lib/ -lgit2
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libgit2/lib/ -lgit2d
else:unix: LIBS += -L$$PWD/libgit2/lib/ -lgit2
INCLUDEPATH += $$PWD/libgit2/include
DEPENDPATH += $$PWD/libgit2/include