Qt5链接错误 [英] Qt5 linking error
问题描述
我通过安装包qt5-default在我的系统(linux mint petra)上安装了Qt5。
我有一个简单的.ui文件和一个main.cpp。
使用uic,我可以将我的.ui文件翻译成main.cpp包含的.h文件。直到现在没有问题。
我运行qmake -project,qmake并make。
编译就好,我得到main.o.
但链接给了我一堆未定义的引用......。
所以,我检查了库。
这是链接器调用:
g ++ -m64 -Wl,-O1 -o qttest main.o -L的/ usr / X11R6 / lib64下-lQt5Gui -L / usr / lib中/ x86_64的-Linux的GNU -lQt5Core -lGL -lpthread
好吧,我搜索了这些库。
据我所知,参数-lQt5Core强制链接器在-L选项指定的目录中查找名为libQt5Core.a的文件。
但是,该文件夹只包含一个libQt5core.so。与其他需要的库一样的东西。
据我所知,.a文件用于静态链接,而.so用于动态链接。
现在,我该如何继续?我应该在网上搜索.a图书馆吗?
为什么qmake会生成一个尝试静态链接的makefile?
我是否缺少一些包?
我从来没有动态链接。我必须添加用于加载.so的代码吗?
我感觉静态链接更容易作为第一步。
最好的问候
使用UIC,我可以在我的.ui文件转换成.h文件
块引用>
$ b $不,你应该让你的构建系统做到这一点。即在.pro
文件中使用FORMS
变量。或者你愿意UIC手动你摸摸你的的.ui
?
<每次重新运行p >据我所知,参数-lQt5Core强制链接器在-L选项指定的目录中查找名为libQt5Core.a的文件。但是,该文件夹只包含一个libQt5core.so。与其他需要的库一样的东西。据我所知,.a文件用于静态链接,而.so用于动态链接。
这只是故事的一半。在支持共享库(即所有现代系统)的系统上,GNU ld将首先查找共享库(即
.so
),并且只有在未找到共享库那么它将查找静态库(.a
)。不管怎样,这不是你的问题。你的问题是,你正在使用的.ui
的文件,也就是,窗口小部件,而你没有告诉你想要的QtWidgets库QMAKE,因为没有<$ C
解决方案:add
<$> $ c $ -lQtWidgets p $ p>QT + =窗口小部件
到您的.pro文件,重新运行qmake,make,就是这样。
I have just installed Qt5 on my system (linux mint petra) by installing the package qt5-default. I have a simple .ui file and a main.cpp. Using uic, I can translate my .ui file into a .h file, which is included by main.cpp. No problem until now.
I run qmake -project, qmake and make. Compiling is just fine, I get main.o. But linking gives me a bunch of "undefined references...".
So, I checked the libraries. This is the linker call:
g++ -m64 -Wl,-O1 -o qttest main.o -L/usr/X11R6/lib64 -lQt5Gui -L/usr/lib/x86_64-linux-gnu -lQt5Core -lGL -lpthread
Ok, so I searched for the libraries. As far as I know, the parameter -lQt5Core forces the linker to look for a file with name libQt5Core.a, in the directories specified with the -L option. However, this folder only contains a libQt5core.so. Same thing with the other needed libraries. As far as I know, .a files are for static linking while .so is for dynamic linking.
Now, how should I proceed? Should I search the internet for a .a library? Why is qmake generating a makefile which tries so static link? Am I missing some packages? I haven't ever dynamically linked. Do I have to add code for loading the .so? I have the feeling statically linking is easier as a first step.
Best Regards
解决方案Using uic, I can translate my .ui file into a .h file
No, you're supposed to let your buildsystem do that. I.e. use the
FORMS
variable in your.pro
file. Or are you willing to rerun uic manually every time you touch your.ui
?As far as I know, the parameter -lQt5Core forces the linker to look for a file with name libQt5Core.a, in the directories specified with the -L option. However, this folder only contains a libQt5core.so. Same thing with the other needed libraries. As far as I know, .a files are for static linking while .so is for dynamic linking.
That's only half of the story. On systems that support shared libraries (i.e. ALL modern systems), GNU ld will look first for shared libraries (i.e.
.so
), and only if a shared library isn't found then it'll look around for static libraries (.a
).Anyhow, that's not your issue. Your issue is that you're using
.ui
files, that is, widgets, and you're not telling qmake that you want the QtWidgets library, because there's no-lQtWidgets
in the linker's command line.Solution: add
QT += widgets
to your .pro file, rerun qmake, make, that's it.
这篇关于Qt5链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!