Compiling a Qt program in Windows XP with MinGW's g++ - c++

I have a stub Qt application and I keep getting compiler errors
#include <QApplication>
int main(int argc, char *argv[])
{
return 0;
}
I used qmake -project and qmake commands and as far as I can tell
they did their job correctly. When I subsequently call make at the command
line I get the following error:
g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT
-DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I
'../../../../qt/include/QtCore' -I'../../../../qt/include/QtCore' -I'../../../..
/qt/include/QtGui' -I'../../../../qt/include/QtGui' -I'../../../../qt/include' -
I'.' -I'c:/qt/include/ActiveQt' -I'release' -I'.' -I'../../../../qt/mkspecs/defa
ult' -o release/Main.o Main.cpp
cc1plus.exe: Invalid option 'threads'
make[1]: *** [release/Main.o] Error 1
make: *** [release] Error 2
My searches on Google tell me that threading is important to keep but not how to
fix this error. Any help will be appreciated.
EDIT (copied from an answer the OP left):
I now get:
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel oc
-Wl,-s -pthread -Wl -Wl,-subsystem,windows -o release/raytrace.exe
object_scr ipt.raytrace.Release -L'c:/qt/lib' -lmingw32 -lqtmain -lQtGui -lgdi32
-lcomdlg3 2 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore -lkernel32
-luser32 - lshell32 -luuid -lole32 -ladvapi32 -lws2_32
g++: unrecognized option `-pthread'
/cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/bin/ld: cannot open -lmsimg32:
No such file or directory collect2:
ld returned 1 exit status make[1]: ***
[release/raytrace.exe] Error 1 make: *** [release] Error 2

++milot
I only use MinGW to compile Qt on Windows and that's the easiest way to make sure you have everything you need.
Here is the link for the Open Source Qt version:
http://trolltech.com/downloads/opensource/appdev/windows-cpp
Use the "Or download Qt with the MinGW compiler included: Size: 149,3 Mb" link.
The other way to use MinGW is to compile Qt with MinGW and then compile your application, but it depends on if you're compiling in MSYS or just using MinGW.

Well I had similar problem before when I was installing MingW downloaded from the web, but in the other hand while installing Qt it will ask you to download the version of MingW which is compatible with Qt. So have you tried installing it when the Qt installer asked you?

Qt 4.5 has Qt Creator 1.1 which is easy to develop applications.
Designing and coding is combined in Qt Creator and mucy easier to use.
you can experience it like using VB IDE(or rather like eclipse,netbeans,etc.)
when run the app. the project is compiled in either in debug or release mode.

Based on the later response from the questioner, not the original question.
From the MSYS prompt run "ls /mingw/lib/libmsimg32.a" and see if you have that file. My installation does (MinGW GCC 3.4.5). If you have that file you may need to add -L/mingw/lib. If you don't have the file you may have missed installing the windows api part of MinGW.
Either way remove -pthread. You're using the Win32 api.
If this doesn't work you need to specify which version of MinGW you're using and, if you're using MSYS, which version of MSYS.

Related

Qt Creator, Compiler in kit for project is being ignored

I am running macOS High Sierra (10.13.2) and Qt 5.10.0. I would like to use OpenMP with my application.
I have added the following flags to my .pro file
QMAKE_CXXFLAGS += -fopenmp
QMAKE_LFLAGS += -fopenmp
LIBS += -fopenmp
The default compilers on macOS do not contain OpenMP. I installed gcc through homebrew which does support OpenMP.
Under the Build & Run -> Compilers tab of Qt Creator, I added the homebrew g++ and gcc compilers (/usr/local/Cellar/gcc/7.2.0/bin/{gcc-7,g++-7}). I then selected the kit that I am using and changed the compiler to be the homebrew installed compiler that I added under the compilers tab.
If I inspect the Makefile generated by Qt Creator after setting this kit and rebuilding the project, I find the CC and CXX are not using the compiler that I have specified.
Here are their values in the Makefile:
CC = /Library/Developer/CommandLineTools/usr/bin/clang
CXX = /Library/Developer/CommandLineTools/usr/bin/clang++
These should be /usr/local/Cellar/gcc/7.2.0/bin/g++-7 and /usr/local/Cellar/gcc/7.2.0/bin/gcc-7.
The compiler output that I get now is:
18:14:48: Starting: "/usr/bin/make"
/usr/local/Cellar/qt/5.10.0/bin/qmake -o Makefile ../Practice/Practice.pro -spec macx-g++ CONFIG+=debug CONFIG+=x86_64 CONFIG+=qml_debug
/Library/Developer/CommandLineTools/usr/bin/g++ -c -pipe -fopenmp -g -std=gnu++11 -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.10 -Wall -W -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../Practice -I. -I/usr/local/Cellar/qt/5.10.0/lib/QtQuick.framework/Headers -I/usr/local/Cellar/qt/5.10.0/lib/QtGui.framework/Headers -I/usr/local/Cellar/qt/5.10.0/lib/QtQml.framework/Headers -I/usr/local/Cellar/qt/5.10.0/lib/QtNetwork.framework/Headers -I/usr/local/Cellar/qt/5.10.0/lib/QtCore.framework/Headers -I. -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/Cellar/qt/5.10.0/mkspecs/macx-g++ -F/usr/local/Cellar/qt/5.10.0/lib -o main.o ../Practice/main.cpp
clang: error: unsupported option '-fopenmp'
make: *** [main.o] Error 1
18:14:49: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project Practice (kit: Desktop)
When executing step "Make"
Why is the Makefile generated by Qt Creator not using the compiler that I am specifying in the kit that I am using?
Because the mkspec macx-g++ you're using will override CC and CXX settings. As a temporary workaround, try setting them in the pro file directly:
QMAKE_CC = /usr/local/Cellar/gcc/7.2.0/bin/gcc-7
QMAKE_CXX = /usr/local/Cellar/gcc/7.2.0/bin/g++-7
You may want to edit the mkspec (or making a new one) for your kit and set those variables there.
To find the mkspec file (qmake.conf):
INSTALLDIR=`qmake -query QT_INSTALL_CONFIGURATION`
MKSPECNAME=`qmake -query QMAKE_SPEC`
cd $INSTALLDIR/mkspecs/$MKSPECNAME
As to why you have to set the compilers twice: Qt Creator is meant to be a generic c++ IDE, thus able to manage non-Qt projects, which don't use qmake but need a compiler anyway.

Building SWipe Application

I'm currently trying to build this application https://github.com/ieatlint/SWipe on macOS and am not having any luck. I don't know much about building applications but this is what I have done so far.
git clone https://github.com/ieatlint/SWipe
cd SWipe
qmake SWipe.pro
make
And that's where I get an error:
make
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -O2 -std=gnu++11 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.10 -Wall -W -fPIC -DQT_NO_DEBUG -DQT_MULTIMEDIA_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -I/usr/local/Cellar/qt/5.9.1/lib/QtMultimedia.framework/Headers -I/usr/local/Cellar/qt/5.9.1/lib/QtWidgets.framework/Headers -I/usr/local/Cellar/qt/5.9.1/lib/QtGui.framework/Headers -I/usr/local/Cellar/qt/5.9.1/lib/QtNetwork.framework/Headers -I/usr/local/Cellar/qt/5.9.1/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/Cellar/qt/5.9.1/mkspecs/macx-clang -F/usr/local/Cellar/qt/5.9.1/lib -o main.o main.cpp
main.cpp:1:10: fatal error: 'QtGui/QApplication' file not found
#include <QtGui/QApplication>
^
1 error generated.
make: *** [main.o] Error 1
I tried adding QT += widgets to the SWipe.pro file by using sudo nano SWipe.pro and adding it under where it says QT += core gui multimedia, but that didn't work.
I just cloned it quickly and had a look. Here is what's wrong with the code:
add widgets to the pro file as you already did (run qmake after this again)
in main.cpp change the include from QtGui/QApplication to just Application (as suggested by AlexanderVX)
Do the same in swipe.h for QtGui/QMainWindow and change it to just QMainWindow
in swipe.cpp change audioFormat.setFrequency( 48000 ) to audioFormat.setSampleRate( 48000 ), assuming that is what it should do as there is no setFrequency function
in swipe.cpp change audioFormat.setChannels( 1 ) to audioFormat.setChannelCount( 1 ), assuming that is what it should do as there is no setChannels function
I did this on my Mac and it builds this way. Have not run it though as I have not really looked into what this thing is doing... that's your job now I guess

Library linking using wxWidgets through Cygwin

I have been trying to get wxWidgets working on Cygwin. So far I have had success by using a mingw compiler available through the cygwin installer.
The build seemed to work fine. The configure message I used was:
configure --host=i686-w64-mingw32 --build=i686-pc-cygwin --enable-static --disable-shared
After that I ran a make and make install and got no errors.
Next I grabbed an example from a tutorial and ran:
i686-w64-mingw32-g++ -c -o hello_world.o hello_world.cpp CXX_FLAGS
i686-w64-mingw32-g++ -o a hello_world.o CXX_FLAGS LIBS
where CXX_FLAGS and LIBS are generated from wx-config -cxxflags and wx-config --libs. This works fine, but when I try to run the executable I get this error:
C:/Users/sam/Documents/cpp/wxwidgets_tutorial/a.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
The libraries I build should be static, so I'm not sure what to do with this message. Any help is greatly appreciated!
Some more info:
wx-config --cxxflags gives the output:
-I/usr/local/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.0 -I/usr/local/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -D__WXMSW__ -mthreads
wx-config --libs give the output:
-L/usr/local/lib -Wl,--subsystem,windows -mwindows /usr/local/lib/libwx_mswu_xrc-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_mswu_webview-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_mswu_qa-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_baseu_net-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_mswu_html-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_mswu_adv-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_mswu_core-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_baseu_xml-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_baseu-3.0-i686-w64-mingw32.a -lpng -ljpeg -ltiff -lexpat -lwxregexu-3.0-i686-w64-mingw32 -lz -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -ladvapi32 -lwsock32 -lgdi32
ls /usr/local/lib:
libwx_baseu_net-3.0-i686-w64-mingw32.a
libwx_baseu_xml-3.0-i686-w64-mingw32.a
libwx_baseu-3.0-i686-w64-mingw32.a
libwx_mswu_adv-3.0-i686-w64-mingw32.a
libwx_mswu_aui-3.0-i686-w64-mingw32.a
libwx_mswu_core-3.0-i686-w64-mingw32.a
libwx_mswu_gl-3.0-i686-w64-mingw32.a
libwx_mswu_html-3.0-i686-w64-mingw32.a
libwx_mswu_media-3.0-i686-w64-mingw32.a
libwx_mswu_propgrid-3.0-i686-w64-mingw32.a
libwx_mswu_qa-3.0-i686-w64-mingw32.a
libwx_mswu_ribbon-3.0-i686-w64-mingw32.a
libwx_mswu_richtext-3.0-i686-w64-mingw32.a
libwx_mswu_stc-3.0-i686-w64-mingw32.a
libwx_mswu_webview-3.0-i686-w64-mingw32.a
libwx_mswu_xrc-3.0-i686-w64-mingw32.a
libwxregexu-3.0-i686-w64-mingw32.a
libwxscintilla-3.0-i686-w64-mingw32.a
wx
EDIT:
Following VZ's advise, I added /usr/i686-w64-mingw32/sys-root/mingw/bin to my path... It compiles!
However when run, the program does not open any window, just exits immediately. Is this still a library problem?
You need to copy the required DLLs (at least libstdc++-6.dll and libgcc_s_sjlj-1.dll) from /usr/i686-w64-mingw32/sys-root/mingw/bin to a directory in your PATH or the application directory (or add this directory itself to your PATH, of course).
You can use cygcheck or (native) dependency walker tool to find which DLL is actually missing.

How to solve mingw32-make.exe exited with code 2 error?

I've installed Qt Open source 4.8.3 library for Windows on Windows 8 Pro x64, Qt Creator 2.6.0 and MingW 4.4.0 manually. From Qt Creator I've setup kits and compilers. I opened the analog clock example comes along with Qt Creator and rebuild the project. The following error are emitted by the compiler.
Running steps for project analogclock...
Starting: "C:\Qt\4.8.3\bin\qmake.exe" C:\Qt\4.8.3\examples\widgets\analogclock\analogclock.pro -r -spec win32-g++
The process "C:\Qt\4.8.3\bin\qmake.exe" exited normally.
Starting: "C:\MingW\bin\mingw32-make.exe"
C:/MingW/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `C:/Qt/4.8.3/examples/widgets/analogclock-build-Desktop-Release'
g++ -c -O2 -Wall -Wextra -fno-exceptions -fno-rtti -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -DQT_NO_DYNAMIC_CAST -I"..\..\..\include\QtCore" -I"..\..\..\include\QtGui" -I"..\..\..\include" -I"..\..\..\include\ActiveQt" -I"release" -I"..\analogclock" -I"." -I"..\..\..\mkspecs\win32-g++" -o release\analogclock.o **..\analogclock\analogclock.cpp**
mingw32-make[1]: Leaving directory `C:/Qt/4.8.3/examples/widgets/analogclock-build-Desktop-Release'
mingw32-make[1]: *** [release/analogclock.o] Error 1
mingw32-make: *** [release] Error 2
The process "C:\MingW\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project analogclock (target: Desktop)
When executing step 'Make'
I've verified that C:/Qt/4.8.3/examples/widgets/analogclock/analogclock.cpp exists. Besides, this project comes with Qt installation and I didn't change anything.
Why is this error occurring and how can i fix it?
It seems your installation of g++ is not clean, so the compiler cannot be launched (this is also what you've said in the comments). Try reinstall, and then you can try to build a hello world program to verify whether you can run g++. Also, please verify that your PATH variable is properly configured for mingw.
Sounds like a bad mingw installation. Are there any other unix-ish things in your %PATH%, i.e. cygwin, or msys, perl, ruby, ... or other versions of mingw?

Code::Blocks linking not working, on prompt it does

I'm having quite a bit of trouble linking a test project of FLTK I'm doing on Code::Blocks, Windows 7.
After spending quite a lot of time understanding how to put the libraries in the correct order, I managed to get the project nearly done. However there's still a linking problem:
mingw32-g++.exe -Wall -fexceptions -IC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0 -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -c C:\Users\Svalorzen\Documents\Projects\test\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\test.exe obj\Debug\main.o -LC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib -mwindows -lfltk -lole32 -luuid -lcomctl32
C:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib/libfltk.a(Fl_Native_File_Chooser.o):Fl_Native_File_Chooser.cxx:(.text+0x1556): undefined reference to `__chkstk_ms'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
1 errors, 0 warnings
However, using the same exact script that Code::Blocks shows, executed on command prompt ( or even msys for what matters ), correctly compiles and links everything. The resulting exe also works.
C:\Users\Svalorzen\Documents\Projects\test>mingw32-g++ -Wall -fexceptions -IC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0 -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -c C:\Users\Svalorzen\Documents\Projects\test\main.cpp -o obj\Debug\main.o
C:\Users\Svalorzen\Documents\Projects\test>mingw32-g++ -o bin\Debug\test.exe obj\Debug\main.o -LC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib -mwindows -lfltk -lole32 -luuid -lcomctl32
C:\Users\Svalorzen\Documents\Projects\test>dir bin\Debug\test.exe
Volume in drive C has no label.
Volume Serial Number is 00E8-6659
Directory of C:\Users\Svalorzen\Documents\Projects\test\bin\Debug
10/05/2012 19:01 661.087 test.exe
1 File(s) 661.087 bytes
0 Dir(s) 66.016.849.920 bytes free
The paths in the instruction are all absolute, so I don't really understand why this is.
What am I doing wrong? What I should check?
EDIT: It turned out that I had a MinGW installation I didn't remember about and Code::Blocks was using that one. I changed it and now everything is fixed.
If your MinGW is up-to-date, then try adding -no-vcproj and -no-dsp and then run mingw32-make confclean.
It turned out that I had a MinGW installation I didn't remember about and Code::Blocks was using that one.
I setup Code::Blocks with the same compiler that created the library and now everything is fine.