QT_VERSION_MAJOR not declared when compiling to 32 bits - c++

I'm working on porting an existing code from Qt4 to Qt5, and compilation works fine on 64 bits (the native system architecture), but fails with a strange error when I try to compile it to 32 bits:
$ QMAKESPEC=linux-g++-32 qmake-qt5
$ make
./create_version.sh
g++ -c -m32 -pipe -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DSLT -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -I. -Iinclude -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtNetwork -isystem /usr/include/qt5/QtCore -I. -I/usr/lib64/qt5/mkspecs/linux-g++-32 -o main.o main.cpp
In file included from /usr/include/qt5/QtCore/qcoreapplication.h:37:0,
from /usr/include/qt5/QtCore/QCoreApplication:1,
from main.cpp:1:
/usr/include/qt5/QtCore/qcoreapplication.h:82:31: error: ‘QT_VERSION_MAJOR’ was not declared in this scope
enum { ApplicationFlags = QT_VERSION
...
I guess this is not related to the code, since the error happens on the first line of my code, which is just an include directive, but don't know how to proceed from here. This is from a Fedora 23 system, if it matters.

The problema was a missing package: qt5-base-devel.i686
After installing it with
sudo dnf install qt5-qtbase-devel.i686
the problem was gone.

Related

How to compile GNU common C++ class framework using C++11 or higher?

I'm working on a project that uses the GNU common C++ class framework (1.8.1-7.el7). The project is written using C++98 (GCC 4.8.5) and I wanted to port it to C++11 or higher. When I compiled it using GCC 9.3.1, I get errors similar to the following:
[me#centos7 ~/github/myproject/utility2]$ make
/bin/sh ../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I.. -I../include -g -O2 -MT utility2.lo -MD -MP -MF .deps/utility2.Tpo -c -o utility2.lo utility2.cpp
libtool: compile: g++ -DHAVE_CONFIG_H -I. -I.. -I../include -g -O2 -MT utility2.lo -MD -MP -MF .deps/utility2.Tpo -c utility2.cpp -fPIC -DPIC -o .libs/utility2.o
In file included from /usr/include/cc++/thread.h:50,
from ../include/myproject/utility1.h:4,
from ../include/myproject/utility2.h:6,
from utility2.cpp:1:
/usr/include/cc++/string.h:734:35: error: friend declaration of 'std::istream& getline(std::istream&, ost::String&, char, size_t)' specifies default arguments and isn't a definition [-fpermissive]
734 | friend __EXPORT std::istream &getline(std::istream &is, String &str, char delim = '\n', size_t size = 0);
| ^~~~~~~
make: *** [utility2.lo] Error 1
I read from here and here that it is impossible to selectively add -fpermissive to compile specific files (in this case, cc++/string.h from the GNU common C++ class framework) using modern GCC versions. I don't want to apply -fpermissive to all my files as that would not be good programming.
Is there a way to compile the GNU Common C++ class framework using C++11 or higher versions without having to broadly apply -fpermissive to all my files in the project? If so, how?

Eclipse Photon CDT Qt5 Project Problems on Ubuntu 18.04

I am trying to use Eclipse to build a Qt5 Widgets app on an Ubuntu 18.04 virtual machine. I'm able to create a Qt project file (.pro) with Eclipse. However, when I try to build it I get an error, "Build not configured correctly." I'd really appreciate any help resolving this. I've used the Eclipse CDT in other projects but this is the first time I've used it with a Qt project. I'd really like to continue using Eclipse for this project.
Details to reproduce follow:
I created a fresh Ubuntu 18.04.1 desktop install on a virtual machine by installing ubuntu-18.04.1-desktop-amd64.iso downloaded from http://releases.ubuntu.com/18.04/
Installed packages necessary to build Qt5 applications and the JRE to run eclipse.
sudo apt-get install qt5-default qtdeclarative5-dev qtquickcontrols2-5-dev
sudo apt-get install qml-module-qtquick-controls
sudo apt-get install g++ make
sudo apt-get install default-jre
Installed Eclipse CDT downloaded from http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/photon/R/eclipse-cpp-photon-R-linux-gtk-x86_64.tar.gz
Launched Eclipse and created a Qt project. In Eclipse I did File -> New -> C/C++Project. Then, I select "Qt C++/QML Application" template and clicked "Next". I set the project name to "hello" and clicked "Finish". I pressed Ctrl-B to build the project but the message, "Build not configured correctly" appeared in the CDT Build Console.
Next I verified that I did have all the build tools installed to build and run the application by building from the command line.
$ cd eclipse-workspace/hello/
$ qmake
Info: creating stash file /home/jdharper/eclipse-workspace/hello/.qmake.stash
$ make
g++ -c -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtQuick -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtQml -isystem /usr/include/x86_64-linux-gnu/qt5/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o hello.o hello.cpp
/usr/lib/qt5/bin/rcc -name hello hello.qrc -o qrc_hello.cpp
g++ -c -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtQuick -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtQml -isystem /usr/include/x86_64-linux-gnu/qt5/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o qrc_hello.o qrc_hello.cpp
g++ -Wl,-O1 -o hello hello.o qrc_hello.o -lQt5Quick -lQt5Gui -lQt5Qml -lQt5Network -lQt5Core -lGL -lpthread
$ ./hello
At this point the application launched correctly.
Here's a screen shot of my Project > Properties.

How to set qmake to C++14 with recent MinGW?

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.

Compile fail on 32bit linux for attribute TI

I have a project built in C++, which compiles great on CentOS 6, 64 bit (VM). However, when I compile it under CentOS 6, 32-bit (VM), I get the error below.
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -O2 -Wall -W -D_REENTRANT -fPIE -Dsecast=1 -DQT_NO_DEBUG -DQT_XML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/usr/lib/qt5/mkspecs/linux-g++ -I../../project -I../../src -I../../../geoip/libmaxminddb-0.5.3/include -I/usr/include/qt5 -I/usr/include/qt5/QtXml -I/usr/include/qt5/QtNetwork -I/usr/include/qt5/QtCore -I../../build/moc -I. -o ../../build/obj/controller.o ../../src/controller.cpp
In file included from ../../src/geoip/geoipdb.h:14,
from ../../src/controller.cpp:34:
../../../geoip/libmaxminddb-0.5.3/include/maxminddb.h:55: error: unable to emulate ‘TI’
What is this TI attribute error and how do I get rid of it?
When I look at the maxminddb.h file the first typedef (below) is where the error is caused.
#if !(MMDB_UINT128_IS_BYTE_ARRAY)
#if MMDB_UINT128_USING_MODE
typedef unsigned int mmdb_uint128_t __attribute__ ((__mode__(TI)));
#else
typedef unsigned __int128 mmdb_uint128_t;
#endif
#endif

QtCreator: `clang: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)`

I'm compiling my Qt 5.1.0 project in QtCreator, and I got the following output:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-c -pipe -O2
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
-mmacosx-version-min=10.6 -std=c++11 -stdlib=libc++ -Wall -W -fPIE
-DQT_NO_DEBUG
-DQT_WIDGETS_LIB
-DQT_GUI_LIB
-DQT_CORE_LIB
-I../../../Qt/Qt5.1.0/5.1.0/clang_64/mkspecs/macx-clang
-I.
-I../../../Qt/Qt5.1.0/5.1.0/clang_64/include
-I../../../Qt/Qt5.1.0/5.1.0/clang_64/include/QtWidgets
-I../../../Qt/Qt5.1.0/5.1.0/clang_64/lib/QtWidgets.framework/Headers
-I../../../Qt/Qt5.1.0/5.1.0/clang_64/include/QtGui
-I../../../Qt/Qt5.1.0/5.1.0/clang_64/lib/QtGui.framework/Headers
-I../../../Qt/Qt5.1.0/5.1.0/clang_64/include/QtCore
-I../../../Qt/Qt5.1.0/5.1.0/clang_64/lib/QtCore.framework/Headers -Ibuild/debug/.moc
-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers
-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/AGL.framework/Headers
-I.
-F/Users/apple/Qt/Qt5.1.0//5.1.0/clang_64/lib
-o build/debug/.obj/main.o ./main.cpp
clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)
Version of XCode: 4.6.3
Version of Mac OS: 10.8.4
How can I solve this problem?
You'll need to use:
-stdlib=libstdc++
instead of:
-stdlib=libc++
This is because the /usr/lib/libc++.dylib is only installed on OSX 10.7+ and you have specified -mmacosx-version-min=10.6.
You could also solve the issue by specifying: -mmacosx-version-min=10.7 and leaving -stdlib=libc++, and this way you will get better C++11 support.