Qt5 C++ application compilation from prompt
-
Try to use these commands:
qmake -makefile
mingw32-make
"./release/app".pro
QT += core gui widgets CONFIG += c++11 SOURCES += \ main.cpp TARGET = appIt works with Qt6. Perhaps this will work with Qt5.
Edited 1/12/2023. Added
widgets.@8Observer8 said in Qt5 C++ application compilation from prompt:
mingw32-make
It does not work with Qt5 on my computer.
In file included from main.cpp:1:
mainwindow.h:4:10: fatal error: QMainWindow: No such file or directory
#include <QMainWindow>
^~~~~~~~~~~~~
compilation terminated.
mingw32-make[1]: *** [Makefile.Release:200: release/main.o] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/lenovo/Projekty/dirtyphp_qt'
mingw32-make: *** [Makefile:38: release] Error 2 -
@8Observer8 said in Qt5 C++ application compilation from prompt:
mingw32-make
It does not work with Qt5 on my computer.
In file included from main.cpp:1:
mainwindow.h:4:10: fatal error: QMainWindow: No such file or directory
#include <QMainWindow>
^~~~~~~~~~~~~
compilation terminated.
mingw32-make[1]: *** [Makefile.Release:200: release/main.o] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/lenovo/Projekty/dirtyphp_qt'
mingw32-make: *** [Makefile:38: release] Error 2@Robert-M said in Qt5 C++ application compilation from prompt:
mainwindow.h:4:10: fatal error: QMainWindow: No such file or directory
Add
QT += widgetsto your pro file as shown in documentation.
-
C:\Users\lenovo>g++ --version
g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\Users\lenovo>make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
Ten program jest darmowy; warunki kopiowania są opisane w źródłach.
Autorzy nie dają ŻADNYCH gwarancji, w tym nawet gwarancji SPRZEDAWALNOŚCI
lub PRZYDATNOŚCI DO KONKRETNYCH CELÓW.
Ten program został zbudowany dla i386-pc-mingw32In Qt Creator I see:
C:\Qt\Tools\mingw730_32\bin\g++.exe
C:\Qt\Tools\mingw730_64\bin\g++.exe
C:\Qt\Tools\mingw900_64\bin\g++.exeIn make file I see:
####### Compiler, tools and options
CC = gcc
CXX = g++
DEFINES = -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN
CFLAGS = -fno-keep-inline-dllexport -g -Wall -W -Wextra $(DEFINES)
CXXFLAGS = -fno-keep-inline-dllexport -g -Wall -W -Wextra -fexceptions -mthreads $(DEFINES)
INCPATH = -I. -I........\Qt\5.13.2\mingw73_64\include -I........\Qt\5.13.2\mingw73_64\include\QtWidgets -I........\Qt\5.13.2\mingw73_64\include\QtGui -I........\Qt\5.13.2\mingw73_64\include\QtANGLE -I........\Qt\5.13.2\mingw73_64\include\QtCore -Idebug -I. -I/include -I........\Qt\5.13.2\mingw73_64\mkspecs\win32-g++
LINKER = g++
LFLAGS = -Wl,-subsystem,windows -mthreads
LIBS = C:\Qt\5.13.2\mingw73_64\lib\libQt5Widgetsd.a C:\Qt\5.13.2\mingw73_64\lib\libQt5Guid.a C:\Qt\5.13.2\mingw73_64\lib\libQt5Cored.a debug\dirtyphp-gui_resource_res.o -lmingw32 C:\Qt\5.13.2\mingw73_64\lib\libqtmaind.a -LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.7.25-winx64\lib -LC:\Utils\postgresql\pgsql\lib -lshell32
QMAKE = C:\Qt\5.13.2\mingw73_64\bin\qmake.exe
IDC = idc
IDL = midl
ZIP = zip -r -9
DEF_FILE =
RES_FILE = debug\dirtyphp-gui_resource_res.o
COPY = copy /y
SED = $(QMAKE) -install sed
COPY_FILE = copy /y
COPY_DIR = xcopy /s /q /y /i
DEL_FILE = del
DEL_DIR = rmdir
MOVE = move
CHK_DIR_EXISTS= if not exist
MKDIR = mkdir
INSTALL_FILE = copy /y
INSTALL_PROGRAM = copy /y
INSTALL_DIR = xcopy /s /q /y /i
QINSTALL = C:\Qt\5.13.2\mingw73_64\bin\qmake.exe -install qinstall
QINSTALL_PROGRAM = C:\Qt\5.13.2\mingw73_64\bin\qmake.exe -install qinstall -exe@Robert-M said in Qt5 C++ application compilation from prompt:
C:\Users\lenovo>g++ --version
g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0OK. So when your
makecommand invokesg++it might be getting this versionIn Qt Creator I see:
C:\Qt\Tools\mingw730_32\bin\g++.exe
C:\Qt\Tools\mingw730_64\bin\g++.exe
C:\Qt\Tools\mingw900_64\bin\g++.exeAnd you appear to have two other
g++versions present on your machineIn make file I see:
CC = gcc
CXX = g++
...
INCPATH = -I. -I........\Qt\5.13.2\mingw73_64\include -I........\Qt\5.13.2\mingw73_64\include\QtWidgets -I........\Qt\5.13.2\mingw73_64\include\QtGui -I........\Qt\5.13.2\mingw73_64\include\QtANGLE -I........\Qt\5.13.2\mingw73_64\include\QtCore -Idebug -I. -I/include -I........\Qt\5.13.2\mingw73_64\mkspecs\win32-g++The
qmakecommand that built this makefile is expectingg++to invoke version 7.3 64Bit and link against Qt libraries built with GCC 7.3 64Bit.
It is possible that GCC 7 and GCC 8 libraries are binary incompatible (do not know, haven't looked) and thisnis the cause of the link-time issue.Try:
set PATH=C:\Qt\Tools\mingw730_64\bin;%PATH% mingw32-make clean mingw32-make -
@jsulm said in Qt5 C++ application compilation from prompt:
QT += widgets
Sorry. I forgot about it.
QT += core gui widgets -
@jsulm said in Qt5 C++ application compilation from prompt:
QT += widgets
Sorry. I forgot about it.
QT += core gui widgets@8Observer8
OK.
undefined reference -
@8Observer8
OK.
undefined reference@Robert-M said in Qt5 C++ application compilation from prompt:
undefined reference
Would you mind to provide more information or how are others supposed to help you based on that information?
-
@8Observer8
OK.
undefined reference@Robert-M, сould you show your current .pro file in full?
-
@Robert-M Have you tried forcing the correct compiler/linker as I requested a few days back?
-
@Robert-M Have you tried forcing the correct compiler/linker as I requested a few days back?