I know there are many duplicates.
This is my Test.pro:
CONFIG += c++14
SOURCES += main.cpp
and my main.cpp:
int main(){}
According to the many duplicates this should give me C++14. However, when I build the project with Qt Creator 4.2.0 with Qt 5.8.0-1 and MinGW gcc 5.3.0-1 installed via the maintenance tool I get
g++ -c -pipe -fno-keep-inline-dllexport -g -std=gnu++1y -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\Test -I. -IC:\Qt\5.8\mingw53_32\include -IC:\Qt\5.8\mingw53_32\include\QtGui -IC:\Qt\5.8\mingw53_32\include\QtANGLE -IC:\Qt\5.8\mingw53_32\include\QtCore -Idebug -IC:\Qt\5.8\mingw53_32\mkspecs\win32-g++ -o debug\main.o ..\Test\main.cpp
which is not the -std=c++14 I expect.
I tried all kinds of tricks from other questions such as
QMAKE_CXXFLAGS_CXX14 = -std=c++14
CONFIG += c++14
QMAKE_CXXFLAGS += -std=c++14
SOURCES += main.cpp
which results in
g++ -c -pipe -fno-keep-inline-dllexport -std=c++14 -g -std=gnu++1y -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\Test -I. -IC:\Qt\5.8\mingw53_32\include -IC:\Qt\5.8\mingw53_32\include\QtGui -IC:\Qt\5.8\mingw53_32\include\QtANGLE -IC:\Qt\5.8\mingw53_32\include\QtCore -Idebug -IC:\Qt\5.8\mingw53_32\mkspecs\win32-g++ -o debug\main.o ..\Test\main.cpp
where the second option overwrites the first, meaning it is still in gnu++1y-mode or just
QMAKE_CXXFLAGS += -std=c++14
SOURCES += main.cpp
which also results in
g++ -c -pipe -fno-keep-inline-dllexport -std=c++14 -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\Test -I. -IC:\Qt\5.8\mingw53_32\include -IC:\Qt\5.8\mingw53_32\include\QtGui -IC:\Qt\5.8\mingw53_32\include\QtANGLE -IC:\Qt\5.8\mingw53_32\include\QtCore -Idebug -IC:\Qt\5.8\mingw53_32\mkspecs\win32-g++ -o debug\main.o ..\Test\main.cpp
I deleted the build directory and the Test.pro.user file to force a build from scratch, nothing gave me C++14.
How do I tell qmake to use C++14?
The version of Qt that you're using doesn't explicitly support the compiler you're using. You can do either one of the following:
Set both QMAKE_CXXFLAGS_CXX14 and QMAKE_CXXFLAGS_GNUCXX14 in your project:
win32-g++ {
QMAKE_CXXFLAGS_CXX14 = -std=c++14
QMAKE_CXXFLAGS_GNUCXX14 = -std=c++14
}
Edit the default values of those two variables as above, in mkspecs/win32-g++/qmake.conf within your Qt installation folder.
Add a new mkspec copied from win32-g++, targeting your compiler, and build your Qt using it. All the project that use that Qt will then behave correctly w.r.t. C++14 support.
Related
I use Qt 5.9.1 and all works fine. Except of one little nuisance: it overrides my -std=C++17.
The project:
#CONFIG += c++14 #makes -std=gnu++1y
#CONFIG += c++17 # is not supported by Qt591
QMAKE_CXXFLAGS += -std=c++17
TARGET = equipment
TEMPLATE = app
SOURCES += ....
....
Compile instructions:
g++ -c -pipe -std=c++17 -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC
-DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_SERIALPORT_LIB -DQT_CORE_LIB
-I../app -I/opt/Qt5.9.1/5.9.1/gcc_64/include -I/opt/Qt5.9.1/5.9.1/gcc_64
/include/QtCore -I. -I/opt/Qt5.9.1/5.9.1/gcc_64/mkspecs/linux-g++
-o test0.o ../test0.cc
We can see two -std= and the second -std=gnu++11 by QMake overrides mine first -std=c++17.
How can I tell QMake to use -std=C++17?
Try CONFIG += c++1z and if it doesn't work pass it to compiler with QMAKE_CXXFLAG.
I wanted to install the python module sip (version 4.17) according to the documentation on my Windows 7 machine:
Download from the official page as described in the documentation
Unzip the repository to the folder C:\Python27\Lib\site-packages\sip-4.17
Configure the package with the command python.exe configure.py in this folder
Building the module mingw32-make fails.
Mingw's make returns the following error message:
mingw32-make[1]: Entering directory 'C:/Python27/Lib/site-packages/sip-4.17/sipgen'
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o main.o main.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o transform.o transform.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o gencode.o gencode.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o extracts.o extracts.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o export.o export.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o heap.o heap.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o parser.o parser.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o lexer.o lexer.c
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -Wl,-s -o sip.exe main.o transform.o gencode.o extracts.o export.o heap.o parser.o lexer.o
mingw32-make[1]: Leaving directory 'C:/Python27/Lib/site-packages/sip-4.17/sipgen'
mingw32-make[1]: Entering directory 'C:/Python27/Lib/site-packages/sip-4.17/siplib'
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python27\include -o siplib.o siplib.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python27\include -o apiversions.o apiversions.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python27\include -o descriptors.o descriptors.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python27\include -o qtlib.o qtlib.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python27\include -o threads.o threads.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python27\include -o objmap.o objmap.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python27\include -o voidptr.o voidptr.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python27\include -o array.o array.c
g++ -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python27\include -o bool.o bool.cpp
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -shared -Wl,-subsystem,console -Wl,-s -o sip.pyd siplib.o apiversions.o descriptors.o qtlib.o threads.o objmap.o voidptr.o array.o bool.o -LC:\Python27\libs -lpython27
C:\Python27\libs/libpython27.a: error adding symbols: File format not recognized
collect2.exe: error: ld returned 1 exit status
Makefile:36: recipe for target 'sip.pyd' failed
mingw32-make[1]: *** [sip.pyd] Error 1
mingw32-make[1]: Leaving directory 'C:/Python27/Lib/site-packages/sip-4.17/siplib'
Makefile:3: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
I have no clue why it failed to compile the code saying File format not recognized. Is it the same mistake as in g++ output: file not recognized: File format not recognized?
Thank you for your help in advance!
Comment:
I followed the following questions too but I want to install it using the zip file - so I know what is installed.
Can't configure pyQt
How to install SIP & PyQT on windows 7
How did you configure SIP? You need to choose a configuration option (see documentation in the docs file of the SIP archive). I got this to work once I chose --platform win32-g++.
Help me to understand, why simple qt application with dynamically loading libraries run under gdb, but more complex is not. Qt Toolkit I use the for both.
This is how my test application builds (lib and exe afterwards):
C:/devtools/mingw-i686-4.8.2-release-posix-dwarf-rt_v3-rev3/mingw32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/juriy/testlib'
g++ -c -pipe -Wall -Wextra -Werror -g -fprofile-arcs -ftest-coverage -O0 -g -frtti -fexceptions -mthreads -Wall -Wextra -DUNICODE -DTESTLIB_LIBRARY -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I'../../../Qt/4.8.6/include/QtCore' -I'../../../Qt/4.8.6/include/QtGui' -I'../../../Qt/4.8.6/include' -I'../../../Qt/4.8.6/include/ActiveQt' -I'debug' -I'../../../Qt/4.8.6/mkspecs/win32-g++' -o debug/testlib.o testlib.cpp
g++ -export-dynamic -lgcov -coverage -mthreads -shared -Wl,--out-implib,debug/libtestlib.a -o debug/testlib.dll debug/testlib.o -L'c:/Qt/4.8.6/lib' -lQtGuid4 -lQtCored4
C:/devtools/mingw-i686-4.8.2-release-posix-dwarf-rt_v3-rev3/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../../i686-w64-mingw32/bin/ld.exe: warning: --export-dynamic is not supported for PE targets, did you mean --export-all-symbols?
mingw32-make[1]: Leaving directory 'C:/Users/juriy/testlib'
g++ -c -pipe -Wall -Wextra -Werror -g -fprofile-arcs -ftest-coverage -O0 -g -frtti -fexceptions -mthreads -Wall -Wextra -DUNICODE -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I'../../../Qt/4.8.6/include/QtCore' -I'../../../Qt/4.8.6/include/QtGui' -I'../../../Qt/4.8.6/include' -I'../testlib' -I'../../../Qt/4.8.6/include/ActiveQt' -I'debug' -I'.' -I'../../../Qt/4.8.6/mkspecs/win32-g++' -o debug/widget.o widget.cpp
g++ -c -pipe -Wall -Wextra -Werror -g -fprofile-arcs -ftest-coverage -O0 -g -frtti -fexceptions -mthreads -Wall -Wextra -DUNICODE -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I'../../../Qt/4.8.6/include/QtCore' -I'../../../Qt/4.8.6/include/QtGui' -I'../../../Qt/4.8.6/include' -I'../testlib' -I'../../../Qt/4.8.6/include/ActiveQt' -I'debug' -I'.' -I'../../../Qt/4.8.6/mkspecs/win32-g++' -o debug/moc_widget.o debug/moc_widget.cpp
g++ -export-dynamic -lgcov -coverage -mthreads -Wl,-subsystem,windows -o debug/test.exe debug/main.o debug/widget.o debug/moc_widget.o -L'c:/Qt/4.8.6/lib' -lmingw32 -lqtmaind -ltestlib -L../testlib/debug -lQtGuid4 -lQtCored4
C:/devtools/mingw-i686-4.8.2-release-posix-dwarf-rt_v3-rev3/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../../i686-w64-mingw32/bin/ld.exe: warning: --export-dynamic is not supported for PE targets, did you mean --export-all-symbols?
mingw32-make[1]: Leaving directory 'C:/Users/juriy/test'
And my complex application building:
g++ -c -pipe -Wall -Wextra -Werror -g -g -frtti -fexceptions -mthreads -Wall -Wextra -DUNICODE -DSIP_LIB -DQWT_DLL -DQT_DLL -DQT_WEBKIT_LIB -DQT_SVG_LIB -DQT_SQL_LIB -DQT_XMLPATTERNS_LIB -DQT_XML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I'../../../../Qt/4.8.6/include/QtCore' -I'../../../../Qt/4.8.6/include/QtNetwork' -I'../../../../Qt/4.8.6/include/QtGui' -I'../../../../Qt/4.8.6/include/QtXml' -I'../../../../Qt/4.8.6/include/QtXmlPatterns' -I'../../../../Qt/4.8.6/include/QtSql' -I'../../../../Qt/4.8.6/include/QtSvg' -I'../../../../Qt/4.8.6/include/QtWebKit' -I'../../../../Qt/4.8.6/include' -I'.' -I'../SIP_Common' -I'../SIP_Qwt' -I'../SIP_Qwt/src' -I'../../../../Qt/4.8.6/include/ActiveQt' -I'debug/mocs' -I'debug/uics' -I'../../../../Qt/4.8.6/mkspecs/win32-g++' -o debug/objs/moc_sbmrscwidget.o debug/mocs/moc_sbmrscwidget.cpp
g++ -export-dynamic -mthreads -shared -Wl,--out-implib,./debug/libWidgets.a -o debug/Widgets.dll object_script.Widgets.Debug -L'c:/Qt/4.8.6/lib' -lCommon -L../SIP_Common/debug -lQwt_4 -L../SIP_Qwt/debug -lQtWebKitd4 -lQtSvgd4 -lQtSqld4 -lQtXmlPatternsd4 -lQtXmld4 -lQtGuid4 -lQtNetworkd4 -lQtCored4
C:/devtools/mingw-i686-4.8.2-release-posix-dwarf-rt_v3-rev3/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../../i686-w64-mingw32/bin/ld.exe: warning: --export-dynamic is not supported for PE targets, did you mean --export-all-symbols?
Tha last illustrates both library and exe building flags, flags the same.
When gdb starts I see in QtCreator gdb output concrete differencies. For simple app gdb starts to load libs like so:
>=library-loaded,id="C:\\Windows\\system32\\ntdll.dll",target-name="C:\\Windows\\system32\\ntdll.dll",host-name="C:\\Windows\\system32\\ntdll.dll",symbols-loaded="0",thread-group="i1"
sLibrary C:\Windows\system32\ntdll.dll loaded
>=library-loaded,id="C:\\Windows\\syswow64\\kernel32.dll",target-name="C:\\Windows\\syswow64\\kernel32.dll",host-name="C:\\Windows\\syswow64\\kernel32.dll",symbols-loaded="0",thread-group="i1"
sLibrary C:\Windows\syswow64\kernel32.dll loaded
>=library-loaded,id="C:\\Windows\\syswow64\\KernelBase.dll",target-name="C:\\Windows\\syswow64\\KernelBase.dll",host-name="C:\\Windows\\syswow64\\KernelBase.dll",symbols-loaded="0",thread-group="i1"
sLibrary C:\Windows\syswow64\KernelBase.dll loaded
>=library-loaded,id="C:\\Users\\juriy\\testlib\\debug\\testlib.dll",target-name="C:\\Users\\juriy\\testlib\\debug\\testlib.dll",host-name="C:\\Users\\juriy\\testlib\\debug\\testlib.dll",symbols-loaded="0",thread-group="i1"
sLibrary C:\Users\juriy\testlib\debug\testlib.dll loaded
But when more complex one starts up, gdb omits the loading and outputs following instead:
>=thread-exited,id="1",group-id="i1"
sThread 1 in group i1 exited
>=thread-group-exited,id="i1"
sThread group i1 exited
>19^error,msg="During startup program exited with code 0xc0000022."
dCOOKIE FOR TOKEN 19 ALREADY EATEN (InferiorRunOk). TWO RESPONSES FOR ONE COMMAND?
dNOTE: INFERIOR EXITED
dState changed from InferiorRunOk(11) to InferiorExitOk(16) [master]
dState changed from InferiorExitOk(16) to InferiorShutdownOk(19) [master]
dState changed from InferiorShutdownOk(19) to EngineShutdownRequested(20) [master]
dQUEUE: SHUTDOWN ENGINE
sExecutable failed: During startup program exited with code 0xc0000022.
PS. There is some warnings about CROSS_COMPILE, should I ignore this?
Here some same question, but it a bit useless because of I couldn't see the decision.
I have Qt-Creator on OpenSUSE. In it a have a C++ project with compiler 'clang'. There I have this '.pro' configuration:
INCLUDEPATH += "/✪Data_Disk⚜✼/Build/include/c++/v1/"
LIBS += "-stdlib=libc++"
LIBS += "/✪Data_Disk⚜✼/Build/lib/libc++abi.a"
QMAKE_CXXFLAGS += -std=c++14 -stdlib=libc++
TARGET = testCpp
SOURCES += main.cpp
And when I compile I got this output:
clang++ -c -pipe -Qunused-arguments -std=c++14 -stdlib=libc++ -g -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/unsupported/linux-clang -I../testCpp -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I/✪Data_Disk⚜✼/Build/include/c++/v1 -I. -I../testCpp -I. -o main.o ../testCpp/main.cpp
I want it to be either:
clang++ -c -pipe -Qunused-arguments -std=c++14 -stdlib=libc++ -g -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/✪Data_Disk⚜✼/Build/include/c++/v1 -I/usr/share/qt4/mkspecs/unsupported/linux-clang -I../testCpp -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -I../testCpp -I. -o main.o ../testCpp/main.cpp
Or:
clang++ -c -pipe -Qunused-arguments -std=c++14 -stdlib=libc++ -g -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/✪Data_Disk⚜✼/Build/include/c++/v1 -o main.o ../testCpp/main.cpp
In other words - I want to either include this path (
-I/✪Data_Disk⚜✼/Build/include/c++/v1
) before the system defined ones or to completely remove them and leave only it. Any ideas?
If you look into qmake source, for example Win32MakefileGenerator::writeStandardParts() or UnixMakefileGenerator::writeMakeParts() you will see that the flags are included in the following order:
QMAKE_CC
QMAKE_CXX
QMAKE_CFLAGS
QMAKE_CXXFLAGS
INCLUDEPATH
...
INCLUDEPATH always goes after the first four. You can use QMAKE_CXXFLAGS and add -I path there:
QMAKE_CXXFLAGS += -I/✪Data_Disk⚜✼/Build/include/c++/v1
My goal is to get rid of some types of compiler warnings. I found out that I can do that by adding compiler flags in my .pro file:
QMAKE_CXXFLAGS += -Wno-unused-variable -Wno-reorder
The problem is that they are added before flags that are generated by Qt build system. I've examined my compiler output:
g++-4.2 -c -pipe -Wno-unused-variable -Wno-reorder -g -gdwarf-2 -arch
x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W
-DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB
So as you can see -Wall goes after my flags and discards them. What should I do to add those flags after ?
Don't use QMAKE_CXXFLAGS but rather override QMAKE_CXXFLAGS_WARN_ON with your own warnings:
QMAKE_CXXFLAGS_WARN_ON = -Wno-unused-variable -Wno-reorder