Qt Creator:未解析的外部符号 [英] Qt Creator: Unresolved External Symbol

查看:396
本文介绍了Qt Creator:未解析的外部符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在挣扎一段时间,在Qt中出现错误:

  mainwindow.obj:-1: LNK2019:未解析的外部符号_git_repository_open在函数public:__thiscall中引用。MainWindow :: MainWindow(class QWidget *)(?? 0MainWindow @@ QAE @ PAVQWidget @@@ Z)
pre>

这显然是一个链接错误,但我还没能找出导致这种情况的原因。这是所有正在Windows上编译,我目标的库是libgit2。



我编译libgit2使用MVSC2010(我也用于我的Qt构建),然后将外部库添加到我的Qt项目中。包括被承认没有问题,但库没有正确链接。因为libgit2是一个C库,我试图将其包含在extern块(也没有exern块)无效:

  externC{
#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 | release):LIBS + = -L $$ PWD / libgit2 / lib / -lgit2d
else:unix:LIBS + = -L $$ PWD / libgit2 / lib / -lgit2

INCLUDEPATH + = $$ PWD / libgit2 / include
DEPENDPATH + = $$ PWD / libgit2 / include


解决方案

看起来您遇到了这个问题:



https://github.com/libgit2/libgit2/issues/741



您可以从这里试用建议:



https://github.com/ libgit2 / libgit2 / pull / 749#issuecomment-6434565


在Windows上使用MSVC工具链构建时,默认构建
使用__stdcall约定。但是这不会反映在
头文件中,所以你必须在自己的
构建中使用/ Gz编译器选项,以便能够成功地链接到libgit2构建的
的方式。如果这不可能或不可取,在初始cmake时设置
-DSTDCALL = OFF选项。



I've been struggling for a while with an error in 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)

This is obviously a linking error, but I haven't been able to figure out what is causing this. This is all being compiled on Windows, and the library that I'm targeting is libgit2.

I compiled libgit2 using MVSC2010 (which I'm also using for my Qt builds), and then added the external library to my Qt project. The includes are being acknowledged without issue, but the library isn't being linked properly. Since libgit2 is a C library, I've tried included the library in an extern block (and also without the exern block) to no avail:

extern "C" {
    #include  <git2.h>
}

Also, the function is in the lib file:

dumpbin /EXPORTS git2.lib
...
_git_repository_open@8
...

The relevant lines which are throwing an error (the first one works if on its own, since it is defined in the git header, but the second line fails upon linking):

git_repository *repo;
git_repository_open(&repo, "/opt/libgit2-test/.git");

The relevant qt.pro file lines:

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

解决方案

It looks like you ran across this problem:

https://github.com/libgit2/libgit2/issues/741

You can try the suggestion from here:

https://github.com/libgit2/libgit2/pull/749#issuecomment-6434565

When building on Windows with the MSVC tool chain, the default build uses the __stdcall convention. However this is not reflected in the header files, so you have to use the /Gz compiler option in your own build as well for being able to successfully link with a libgit2 built that way. If this is not possible or not desirable, set the -DSTDCALL=OFF option when doing the initial cmake.

这篇关于Qt Creator:未解析的外部符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆