0
votes

I am trying to build a simple QT program with MinGW compiler. I want to eventually port my Linux developed QT/C++ program in to windows. I downloaded QT_4.3.5 (This what my program uses) and MinGW from their site. I believe this a 32 bit compiler. I am using "cmd" to build the program similar to how I built it in Linux. My program is shown below.

#include <QApplication>
#include <QPushButton>
#include <cstdio>

int main(int argc, char *argv[])   //This should work with QT4?
{
printf("Hello\n");
QApplication app(argc,argv);
QPushButton hello ("Hello world!");
hello.resize(100,30);
hello.show();
return app.exec();
} 

I was able to build and run this program successfully in Linux 5.7. So, in windows I created a "main.cpp" file and use qmake to create both the .pro file and the Makefile. I am using qmake from the QT4.3.5. I used "qmake -project" and qmake. It successfully built both the .pro file and the Makefile in windows. But when I run make it gives me a "unrecognized commandline option '-Wl' "

I believe there could be a compatibility issue with qmake version and minGW. The relevant line in the Makefile is,

LFLAGS        =        -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows

I then tried to remove -Wl and it gives errors saying can't find "-enable-auto-import", "-enable-runtime-pseudo-reloc", "-s", "-subsystem,windos" no such file or directory.

1) How should I debug this issue?

2) Should I try minGW64 version?

------------------------------------Edited-------------------------------------

I decided to get a newer version of QT to test. So, I have installed QT 5.6.3 and I am also using minGW4.9 that come with QT5.6.3. I have also created the QT project file (.pro) myself.

TEMPLATE = app
TARGET = QT_Simple
INCLUDEPATH += .

# Input
SOURCES += main.cpp

LIBS += -L"C:\Qt\Qt5.6.3\5.6.3\mingw49_32\lib" \
 -L"C:\Qt\Qt5.6.3\5.6.3\mingw49_32\lib" \
 -lmingw32 \
 -lqtmain \
 -lQt5Core \
 -lQt5Gui \

Then I run "qmake" to create the Makefile. Here's the relevant sections. It looks little different from the previous qmake

####### Compiler, tools and options

CC            = gcc
CXX           = g++
DEFINES       = -DUNICODE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB - 
DQT_NEEDS_QMAIN
CFLAGS        = -pipe -fno-keep-inline-dllexport -O2 -Wall -Wextra 
$(DEFINES)
CXXFLAGS      = -pipe -fno-keep-inline-dllexport -O2 -std=gnu++0x -frtti - 
Wall -Wextra -fexceptions -mthreads $(DEFINES)
INCPATH       = -I. -I. -IC:/Qt/Qt5.6.3/5.6.3/mingw49_32/include - 
IC:/Qt/Qt5.6.3/5.6.3/mingw49_32/include/QtGui - 
IC:/Qt/Qt5.6.3/5.6.3/mingw49_32/include/QtANGLE - 
IC:/Qt/Qt5.6.3/5.6.3/mingw49_32/include/QtCore -Irelease - 
IC:/Qt/Qt5.6.3/5.6.3/mingw49_32/mkspecs/win32-g++ 
LINKER      =        g++
LFLAGS        =        -Wl,-s -Wl,-subsystem,windows -mthreads
LIBS        =        -LC:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib - 
LC:/utils/my_sql/my_sql/lib -LC:/utils/postgresql/pgsql/lib - 
LC:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib -lmingw32 
C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libqtmain.a -lshell32 
C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Core.a 
C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Gui.a 
C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Core.a 
QMAKE         = C:/Qt/Qt5.6.3/5.6.3/mingw49_32/bin/qmake.exe
IDC           = idc
IDL           = midl
...........

I know the library files are in the above directories (ex. libQt5Core.a, libQt5Gui.a, etc). But it gives me an udefined reference error. I believe the linker can't find the files.

C:\Users\Administrator\Documents\QT_Test\QT_Simple>mingw32-make
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'C:/Users/Administrator/Documents/QT_Test/QT_Simple'
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release/QT_Simple.exe release/main.o  -LC:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib
 -LC:/utils/my_sql/my_sql/lib -LC:/utils/postgresql/pgsql/lib -LC:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib -lmingw32 
 C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libqtmain.a -lshell32 C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Core.a 
 C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Gui.a C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Core.a

release/main.o:main.cpp:(.text+0x4d): undefined reference to `_imp___ZN12QApplicationC1ERiPPci'
release/main.o:main.cpp:(.text+0x7f): undefined reference to `_imp___ZN11QPushButtonC1ERK7QStringP7QWidget'
release/main.o:main.cpp:(.text+0xb0): undefined reference to `_imp___ZN7QWidget6resizeERK5QSize'
release/main.o:main.cpp:(.text+0xbc): undefined reference to `_imp___ZN7QWidget4showEv'
release/main.o:main.cpp:(.text+0xc2): undefined reference to `_imp___ZN12QApplication4execEv'
release/main.o:main.cpp:(.text+0xcd): undefined reference to `_imp___ZN11QPushButtonD1Ev'
release/main.o:main.cpp:(.text+0xd6): undefined reference to `_imp___ZN12QApplicationD1Ev'
release/main.o:main.cpp:(.text+0x120): undefined reference to `_imp___ZN12QApplicationD1Ev'
release/main.o:main.cpp:(.text+0x155): undefined reference to `_imp___ZN11QPushButtonD1Ev'
C:/Qt/Qt5.6.3/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: release/main.o: 
bad reloc address 0x20 in section `.eh_frame'
C:/Qt/Qt5.6.3/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../.
./i686-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Makefile.Release:61: recipe for target 'release/QT_Simple.exe' failed
mingw32-make[1]: *** [release/QT_Simple.exe] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/Administrator/Documents/QT_Test/QT_Simple'
makefile:34: recipe for target 'release' failed
mingw32-make: *** [release] Error 2

I am not sure why it can't find the references. Does it have to do with not using the DLL files (libQt5Core.dll, etc). Am I linking properly?

1
Try to use mingw32-make instead of make, becaise make may be a command from MSVC or something else.Michael
It is actually using mingw-32-makenmr

1 Answers

0
votes

The issue was with my QT project file (.pro). I added the following line and it compiled and ran successfully.

QT       += core gui widgets

The final QT_simple.pro file looks like the following,

QT       += core gui widgets

TEMPLATE = app
TARGET = QT_Simple
INCLUDEPATH += .

# Input
SOURCES += main.cpp

LIBS += -L"C:\Qt\Qt5.6.3\5.6.3\mingw49_32\lib" \
  -L"C:\Qt\Qt5.6.3\5.6.3\mingw49_32\lib" \
  -lmingw32 \
  -lqtmain \
  -lQt5Core \
  -lQt5Gui \

Thanks for the help!