Qt5 C++ application compilation from prompt
-
@Robert-M said in Qt5 C++ application compilation from prompt:
Still undefined reference problem
Why don't you post the command line which was used?
-
@Robert-M What version of MingW
g++andmakeare in use to build the project? Is this the MingW tool chain that is installed by the Qt online installer or another copy? Is this exactly the same compiler that is defined and works in Qt Creator?g++ --version make --version -
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 -
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. -
I created test.pro
C:\Users\lenovo\Projekty\dirtyphp_qt>C:\Qt\5.13.2\mingw73_64\bin\qmake.exe -makefile test.pro
C:\Users\lenovo\Projekty\dirtyphp_qt>mingw32-make
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'C:/Users/lenovo/Projekty/dirtyphp_qt'
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\app.exe release/main.o C:\Qt\5.13.2\mingw73_64\lib\libQt5Gui.a C:\Qt\5.13.2\mingw73_64\lib\libQt5Core.a -lmingw32 C:\Qt\5.13.2\mingw73_64\lib\libqtmain.a -LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.7.25-winx64\lib -LC:\Utils\postgresql\pgsql\lib -lshell32
release/main.o: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile.Release:65: release/app.exe] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/lenovo/Projekty/dirtyphp_qt'
mingw32-make: *** [Makefile:38: release] Error 2 -
I don't know. I just post my result:
E:_Projects\Qt\test>mingw32-make
C:/Qt6/Tools/mingw810_64/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'E:/_Projects/Qt/test'
g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I. -IC:/Qt6/6.2.0/mingw81_64/include -IC:/Qt6/6.2.0/mingw81_64/include/QtGui -IC:/Qt6/6.2.0/mingw81_64/include/QtCore -Irelease -I/include -IC:/Qt6/6.2.0/mingw81_64/mkspecs/win32-g++ -o release\main.o main.cpp
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\app.exe release/main.o C:\Qt6\6.2.0\mingw81_64\lib\libQt6Gui.a C:\Qt6\6.2.0\mingw81_64\lib\libQt6Core.a -lmingw32 C:\Qt6\6.2.0\mingw81_64\lib\libQt6EntryPoint.a -lshell32
mingw32-make[1]: Leaving directory 'E:/_Projects/Qt/test' -
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?