0

I am putting together an example project structure for a desktop application stack including Qt, Googletest, CMake, and C++. The goal here is to have a cross-platform project structure that people can copy from github to insert their code for their C or C++ static library (used by their UI), automated unit testing for their library, and UI (Qt5) code in a well organized sample project. I'll eventually write scripts (or use RPMs) to pull down the dependencies for the project and build the project's static library and link it to the UI, which it also packages into an executable.

I have all parts of the stack working well except Qt. I don't want to use QtCreator because that creates additional dependency complication and increases install size by quite a bit, so I'm compiling everything on command line. On both Windows and Linux (Ubuntu), I have an issue where after I make the release directory or makefile with qmake, the object file or makefile (respectively) does not link Qt to the project. How do I tell qmake to link libraries (including Qt itself) in the makefile or object file it builds?

As additional background, I am using Designer to make .ui files for the project. I turn them into header files using

uic -o ui_mainwindow.h mainwindow.ui

Assuming the static library for the actual code part of the project has already been compiled, my build steps for the UI are:

qmake -project
qmake ui.pro
nmake release

And the output I get is:

cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -I. -I. -IC:\qt5\qtbase\include -IC:\qt5\qtbase\include\QtGui -IC:\qt5\qtbase\include\QtCore -Irelease -IC:\qt5\qtbase\mkspecs\win32-msvc -Forelease\ @C:\Users\User\AppData\Local\Temp\nmA4E2.tmp                                                   mainwindow.cpp                                                                                                                  
link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:release\ui.exe @C:\Users\User\AppData\Local\Temp\nmAACF.tmp                                   
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QWidget::QWidget(class QWidget *,class QFlags<enum Qt::WindowType>)" (__imp_??0QWidget@@QAE@PAV0@V?$QFlags@W4WindowType@Qt@@@@@Z) referenced in function "public: void __thiscall Ui_MainWindow::setupUi(class QMainWindow *)" (?setupUi@Ui_MainWindow@@QAEXPAVQMainWindow@@@Z)                                                                                                            
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QWidget::~QWidget(void)" (__imp_??1QWidget@@UAE@XZ) referenced in function "public: virtual void * __thiscall QWidget::`scalar deleting destructor'(unsigned int)" (??_GQWidget@@UAEPAXI@Z) 

followed by many more errors of the same LNK2019 type, which indicates to me that Qt is not properly linked. This build is on Windows 10, but very similar errors occur on Ubuntu 16.04

Just in case this is something wrong in my code and not in the linking, here's my mainwindow.cpp file:

#include <QtWidgets/QMainWindow>
#include <QtWidgets/QApplication>
#include "ui_mainwindow.h"

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    QMainWindow *window = new QMainWindow;
    Ui::MainWindow ui;
    ui.setupUi(window);
    window->show();
    return app.exec();
}

The ui_mainwindow.h file is generated by uic from a Qt designer ui file, and it is very long so I will not include it here.

So just to repeat the question for the sake of redundancy, how do I tell qmake to link libraries (including Qt itself) in the makefile or object file it builds?

Sam Rappl
  • 1
  • 1
  • 1
    "I don't want to use QtCreator because that creates additional dependency complication" - That's nonsense. Qtcreator is just an IDE - a glorified editor that knows how to compile stuff. It does *not* introduce any dependencies what-so-ever. – Jesper Juhl Jul 07 '19 at 20:10
  • 1
    The project file created by 'qmake -project' might be not complete (see qmake --help). You might have to add the Qt modules you want to use like 'QT += core gui widgets'. – Mathias Schmid Jul 07 '19 at 21:11
  • `__declspec(dllimport)` means it wants an import library for a dll. – drescherjm Jul 08 '19 at 00:30
  • @JesperJuhl not true. I'm trying to create a pipeline for a desktop application stack here. If I require my user to use a specific IDE in order to make my build pipeline work, then I've made them install unnecessary software. – Sam Rappl Jul 08 '19 at 01:02
  • @MathiasSchmid Thank you so much! That was exactly the problem. Now everything works great! – Sam Rappl Jul 08 '19 at 01:04

0 Answers0