Unsolved Qt5 C++ application compilation from prompt
-
I am quite new to Qt. I have written Qt5 C++ application which compiles fine in Qt Creator. But when I compile from command prompt I receive errors:
g++ -Wl,-subsystem,windows -mthreads -o debug\dirtyphp-gui.exe @object_script.dirtyphp-gui.Debug 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
debug/main.o: In functionZ5qMainiPPc': C:\Users\lenovo\Projekty\dirtyphp_qt/main.cpp:16: undefined reference to
_imp___ZN12QApplicationC1ERiPPci'
C:\Users\lenovo\Projekty\dirtyphp_qt/main.cpp:18: undefined reference to_imp___ZN11QMessageBoxC1EP7QWidget' C:\Users\lenovo\Projekty\dirtyphp_qt/main.cpp:19: undefined reference to
_imp___ZN11QMessageBox7setIconENS_4IconE'
C:\Users\lenovo\Projekty\dirtyphp_qt/main.cpp:20: undefined reference to_imp___ZN11QMessageBox7setTextERK7QString' C:\Users\lenovo\Projekty\dirtyphp_qt/main.cpp:21: undefined reference to
_imp___ZN7QDialog4execEv'
C:\Users\lenovo\Projekty\dirtyphp_qt/main.cpp:18: undefined reference to_imp___ZN11QMessageBoxD1Ev' C:\Users\lenovo\Projekty\dirtyphp_qt/main.cpp:25: undefined reference to
_imp___ZN11QMessageBoxC1EP7QWidget'What is wrong with my project? How to correct errors?
-
Which commands do you use to build in terminal?
Are you using static Qt build? (a bit weird to see it linking to .a files)
Is the path correct?
C:\Qt\5.13.2\mingw73_64\lib\libQt5Widgetsd.a
-
Is the path correct? C:\Qt\5.13.2\mingw73_64\lib\libQt5Widgetsd.a
Yes, it is correct.
Are you using static Qt build?
No, I am not.
Which commands do you use to build in terminal?cd C:\Users\lenovo\Projekty\dirtyphp_qt
C:\Qt\5.13.2\mingw73_64\bin\qmake.exe dirtyphp_qt.pro
make clean
if "%1"=="" (set g=debug) else (set g=%1)
make %g%
rem "C:\Program Files (x86)\CQtDeployer\1.5\cqtdeployer.bat" -bin dirtyphp-gui -qmake "C:\Qt\5.13.2\mingw73_64\bin\qmake.exe" -targetDir "C:/Users/lenovo/Projekty/dirtyphp"
"C:\Qt\5.13.2\mingw73_64\bin\windeployqt.exe" --dir "C:/Users/lenovo/Projekty/dirtyphp" "C:/Users/lenovo/Projekty/dirtyphp_qt/debug/dirtyphp-gui.exe"
C:\Users\lenovo\Projekty\dirtyphp\dirtyphp.exe >C:\Users\lenovo\Projekty\dirtyphp-website\app_edit\Views\usage\dirtyphp_windows.txt
del /S/Q C:\Users\lenovo\Projekty\dirtyphp\bin
del /Q C:\Users\lenovo\Projekty\dirtyphp\Qt5*.dll
del /Q C:\Users\lenovo\Projekty\dirtyphp\opengl32sw.dll
del /Q C:\Users\lenovo\Projekty\dirtyphp\lib*.dll
if "%g%"=="release" goto release_dlls
if "%g%"=="debug" goto debug_dlls
:cont_xcopy:
xcopy %g%\dirtyphp-gui.exe C:\Users\lenovo\Projekty\dirtyphp\ /Y
rem xcopy %g%\dirtyphp-gui.bat C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy dirtyphp.ico C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy dirtyphp.png C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy read_me.txt C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy dirtyphp_license.txt C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy qt_gnu_lgpl.txt C:\Users\lenovo\Projekty\dirtyphp\ /Y
pause
exit
:release_dlls:
xcopy C:\Qt\5.13.2\mingw73_64\bin\Qt5Core.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Qt\5.13.2\mingw73_64\bin\Qt5Widgets.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Qt\5.13.2\mingw73_64\bin\Qt5Gui.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Qt\5.13.2\mingw73_64\bin\Qt5Svg.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\release\opengl32sw.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\release\libEGLd.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\release\libgcc_s_seh-1.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\release\libGLES2d.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\release\libstdc++-6.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\release\libwinpthread-1.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
goto cont_xcopy
:debug_dlls:
xcopy C:\Qt\5.13.2\mingw73_64\bin\Qt5Cored.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Qt\5.13.2\mingw73_64\bin\Qt5Widgetsd.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Qt\5.13.2\mingw73_64\bin\Qt5Guid.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Qt\5.13.2\mingw73_64\bin\Qt5Svgd.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\debug\opengl32sw.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\debug\libEGLd.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\debug\libgcc_s_seh-1.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\debug\libGLES2d.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\debug\libstdc++-6.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
xcopy C:\Users\lenovo\Projekty\dirtyphp_qt\debug\libwinpthread-1.dll C:\Users\lenovo\Projekty\dirtyphp\ /Y
goto cont_xcopy -
It might help if you also add Qt dir to path:
set PATH=C:\Qt\5.13.2\mingw73_64\bin;%PATH%
-
It didn't help. Still the problem exists.
-
@Robert-M
When you compiledC:\Users\lenovo\Projekty\dirtyphp_qt/main.cpp
to producedebug/main.o
what command line did that use? have you tried deleting that object file and recompiling from scratch? -
I deleted main.o and recompiled - still same error.
I don't know how to check what command line is used. Do you want to see Makefile? Below project file:#-------------------------------------------------
Project created by QtCreator 2021-05-14T13:34:22
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = dirtyphp-gui
win32:TARGET = dirtyphp-gui
unix:TARGET = dirtyphp-guiwin32:TARGET_CUSTOM_EXT = .exe
unix:TARGET_CUSTOM_EXT =
win32:DEPLOY_COMMAND = C:\Qt\5.13.2\mingw73_64\bin\windeployqt.exe C:\Users\lenovo\Projekty\dirtyphp
unix:DEPLOY_COMMAND = /home/robert/bin/CQtDeployer/1.5/cqtdeployer.sh -bin dirtyphp-gui -qmake /usr/bin/qmake -targetDir /home/robert/Projekty/dirtyphp/include Qt includes: INCLUDEPATH +=
TEMPLATE = app
win32:ProgramData.path = C:/Users/lenovo/Projekty/dirtyphp
unix:ProgramData.path = /home/robert/Projekty/dirtyphp
ProgramData.files += read_me.txt
ProgramData.files += qt_gnu_lgpl.txt
ProgramData.files += dirtyphp_license.txt
ProgramData.files += dirtyphp.ico
ProgramData.files += dirtyphp.pngINSTALLS += ProgramData
added by Robert:
CONFIG *= dll
CONFIG += debug
CONFIG( debug, debug|release ) {
DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/debug/$${TARGET}$${TARGET_CUSTOM_EXT}))
} else {
DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/release/$${TARGET}$${TARGET_CUSTOM_EXT}))
}QMAKE_POST_LINK += $${DEPLOY_COMMAND} # $${DEPLOY_TARGET}
The following define makes your compiler emit warnings if you use
any feature of Qt which has been marked as deprecated (the exact warnings
depend on your compiler). Please consult the documentation of the
deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
You can also make your code fail to compile if you use deprecated APIs.
In order to do so, uncomment the following line.
You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES +=
main.cpp
mainwindow.cpp
aboutdialog.cpp
../dirtyphp_cpp/src/common.cpp
../dirtyphp_cpp/src/common1.cpp
../dirtyphp_cpp/pugixml/src/pugixml.cpp
frameworksdialog.cpp
global.cpp
otheroptionsdialog.cpp
recentapplicationsdialog.cpp
viewerdialog.cppHEADERS +=
mainwindow.h
aboutdialog.h
frameworksdialog.h
global.h
otheroptionsdialog.h
recentapplicationsdialog.h
viewerdialog.hFORMS +=
aboutdialog.ui
mainwindow.ui
frameworksdialog.ui
otheroptionsdialog.ui
recentapplicationsdialog.ui
viewerdialog.uiRESOURCES +=
dirtyphp.qrcRC_ICONS = dirtyphp.ico
-
@Robert-M
Please help. -
@Robert-M said in Qt5 C++ application compilation from prompt:
I don't know how to check what command line is used
Simply check the compiler output
-
@Robert-M It is possible you have a collection of bits of several builds, and of several sets of QT DLLS that you copy into your source folder (why?). You should get out of the habit of building in-source, and shadow build instead (as Qt Creator does). You can delete the entire shadow build directory at any time to guarantee a clean build and your source directories rename untouched.
In your PRO file these lines
TEMPLATE = app
andCONFIG *= dll
do not make sense together. If you are building an application then you are not building a library DLL.
TheCONFIG += debug
and related lines should probably be omitted, with the type of build passed in atqmake
time (as below). It will default to release IIRC. The build products all go into their natural place in your disposable build directory.For the purposes of debugging the build, remove the QMAKE_POST_LINK.
So, does this fail?
cd C:\Users\lenovo\Projekty mkdir dirtyphp_qt_Debug_Build cd dirtyphp_qt_Debug_Build C:\Qt\5.13.2\mingw73_64\bin\qmake.exe CONFIG+=debug ..\dirty_php_qt\dirtyphp_qt.pro make
-
Still undefined reference problem.
-
@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++
andmake
are 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 = app
It 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' -
@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 += widgets
to your pro file as shown in documentation.
-
@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
make
command 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
qmake
command 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