I am trying to build my Qt project with C++11 standard. I added this flag in the build steps, additional argument option, in the Qt Creator :
-std=c++11
But I got this error while building :
Unknown option -std=c++11
g++ version info : g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Any ideas ?
Use the qmake project file, add this line: QMAKE_CXXFLAGS += -std=c++11
LE: also 4.6.3 might not support C++11 (as far as i know 4.7 and higher support -std=c++11) so the option for the 0x features implemented might be: QMAKE_CXXFLAGS += -std=c++0x
If you are using Qt5, add CONFIG += c++11 to your .pro file, that works on all systems.
Related
I'm porting my Qt app to Linux for x86 architecture, and since the last official release for that platform is 5.5, I'm trying to do my own build of Qt 5.11.3. I want to use fontconfig to enable use of system fonts. My build platform is Centos 7.5, and I'm using a GCC toolchain which builds x86 binaries with -m32 switch.
The problem is, I can't get it to see the fontconfig library. I've installed it with the package fontconfig-devel-2.13.0-4.3.el7.i686
When running configure with the option -fontconfig, I get the following error message:
ERROR: Feature 'fontconfig' was enabled, but the pre-condition '!config.win32 && features.system-freetype && libs.fontconfig' failed.
My understanding from this is that I have to use -system-freetype and can't use -qt-freetype, but when I try that (also with -feature-freetype), I get this message:
ERROR: Feature 'system-freetype' was enabled, but the pre-condition 'features.freetype && libs.freetype' failed.
The relevant messages in config.log are:
looking for library freetype
Trying source 0 (type pkgConfig) of library freetype ...
pkg-config use disabled globally.
=> source produced no result.
Trying source 1 (type freetype) of library freetype ...
+ cd /home/myuser/qt-build/config.tests/freetype && /home/myuser/qt-build/qtbase/bin/qmake "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" -early "CONFIG += cross_compile" 'LIBS += -lfreetype' /home/myuser/qt-build/config.tests/freetype
+ cd /home/myuser/qt-build/config.tests/freetype && MAKEFLAGS= /usr/bin/gmake
> g++ -c -m32 -pipe -O2 -std=gnu++11 -w -fPIC -I. -I/home/myuser/qt-everywhere-src-5.11.3/qtbase/mkspecs/linux-g++-32 -o main.o main.cpp
> main.cpp:2:22: fatal error: ft2build.h: No such file or directory
> #include <ft2build.h>
> ^
> compilation terminated.
> gmake: *** [main.o] Error 1
=> source failed verification.
test config.qtbase_gui.libraries.freetype FAILED
Now, I do also get this message:
WARNING: Cross compiling without sysroot. Disabling pkg-config
which I understand is the source of the "source 0" failure. I have however tried to point configure manually point it to the freetype include directory, by passing FREETYPE_INCDIR=/usr/include/freetype2 to configure; however, as can be seen in the log file, the value does not seem to be used when detecting freetype.
Am I missing a trick here, or are the configure scripts broken? And if it's the latter, is there a way to work around this?
EDIT: For completeness, the environment for running configure:
CFLAGS=-m32
CXXFLAGS=-m32 --std=c++1x
Configure flags:
-opensource
-xplatform linux-g++-32
-nomake tests -nomake examples -nomake tools
-prefix /home/myuser/qt_install/
-qpa xcb
-no-use-gold-linker
-icu ICU_PREFIX=/home/myuser/icu_install ICU_LIBS="-licui18n -licuuc -licudata"
-no-opengl
-fontconfig -feature-freetype -system-freetype FREETYPE_INCDIR=/usr/include/freetype2
Try using the Freetype library that is included inside Qt's sources: when running configure use the flag "-qt-freetype"
I've found it's possible to work around this by setting CPATH (and LIBRARY_PATH to point at a specific build of Freetype which it turned out I needed as well). It looks like the fact that FREETYPE_* variables are ignored when detecting the presence of Freetype is indeed a bug in the config scripts.
I would like to migrate from Qt 5.6 to Qt 5.7 on my workstation running centos 6.7. Everything's fine with Qt 5.6 but i am facing the following issue with Qt 5.7 after i have downloaded and installed it.
I am trying to run the elasticnode examples to check the installation but i have the following build error:
cc1plus: error: unrecognized command line option "-std=gnu++11"
This error is related to the version of gcc which is 4.4.7 and does not recognize this option. The compiler flag used by Qt 5.7 to activate c++11 features is -std=gnu++11 and with Qt 5.6 it was -std=gnu++0x and only this last flag is recognized by gcc.
In the .pro file of the elasticnodes example, nothing is set and so i assume that c+11 was disabled by default as described in the documentation http://doc.qt.io/qt-5/qmake-variable-reference.html#config but this is not consistent with the gcc command line that is finally generated by qmake.
So my question is , how to remove the new flag and set the old flag back in the .pro file , that is -std=gnu++0x instead of -std=gnu++11 ?
I have tried to add the following lines :
CONFIG -= c++11
QMAKE_CXXFLAGS += -std=gnu++0x
but i get this error :
/opt/Qt5.7.0/5.7/gcc_64/include/QtCore/qbasicatomic.h:61: error: #error "Qt requires C++11 support"
Does anyone knows how to properly set this flag ?
Qt 5.7 requires a C++11 compiler. The minimum supported GCC version is therefore GCC 4.6 (but higher versions are highly recommended). You can install a devtoolset (say, devtoolset-2, see here) to get a better compiler.
I'm writing a QML application using Qt 5.7 on Ubuntu 14.04. I prefer to use an editor other than Qt Creator, so it makes it slightly cumbersome to launch Qt Creator and switch to it just to press Ctrl-R each time I want to run. I'd like to compile and launch my app from the command line.
Following this answer and then this answer I was able to install qmake and make it the default:
sudo apt-get install qt5-qmake
sudo apt-get install qt5-default
Following this answer I am copying the qmake build command listed by Qt Creator in the Project tab and successfully building the make file:
qmake qt-client.pro -r -spec linux-g++
However, when I run make (on my already-working-in-Qt-Creator code) I get:
phrogz#Slub:~/Code/rb3jay/qt-client$ make
g++ -c -pipe -O2 -std=c++0x -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -I. -I/usr/include/qt5 -I/usr/include/qt5/QtQuick -I/usr/include/qt5/QtQml -I/usr/include/qt5/QtNetwork -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o main.o main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:6:36: error: ‘AA_EnableHighDpiScaling’ is not a member of ‘Qt’
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
^
make: *** [main.o] Error 1
I'm guessing that perhaps the version of Qt being picked up by qmake or g++ is not the 5.7 version Qt Creator is using, since AA_EnableHighDpiScaling was added in Qt 5.6.
The full generated Makefile includes
99 references to /usr/include/qt5 and 179 references to /usr/lib/x86_64-linux-gnu/qt5. Qt 5.7 is installed in /home/phrogz/Qt5.7.0. Obviously I need to modify something in the qmake command to get this pointing elsewhere.
How can I get this to work? Do I need to somehow remove an older version of qt libraries installed by Ubuntu? Point some configuration to the version of Qt 5.7 that's now installed (by the Qt Installer) in my home directory? Replace existing/old Qt directories with symlinks?
Or you can use CMake:
cmake_minimum_required (VERSION 2.8.11)
project(myproject)
find_package(Qt5 5.7.0 REQUIRED COMPONENTS
Core
Quick
Widgets
)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_executable(${PROJECT_NAME}
main.cpp
)
target_link_libraries(${PROJECT_NAME}
Qt5::Core
Qt5::Quick
Qt5::Widgets
)
I'm new to Qt and have just installed the latest version of Linux (mint Ubuntu 13.04) to begin my programming. To begin with I have installed Qt4 using the github BuildScript (this also installs QtCreater, QtDesigner, QtAssistant, and QtLinguist). I have also installed PySide, as I plan to do a little Python gui programming as well. I did not consciously install qt5, but it appears, at some point along the line I did.
The following program from the QT tutorial illustrates my issue:
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
delete label;
return app.exec();
}
Now running:
..] $ qmake -project
..] $ qmake
..] $ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB
-DQT_CORE_LIB -I/usr/share/qt5/mkspecs/linux-g++-64 -I. -I.
-I/usr/include/qt5 -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I.
-o helloWorld.o helloWorld.cpp helloWorld.cpp:1:24:
fatal error: QApplication: No such file or directory compilation terminated.
which obviously means gcc isn't finding QApplications in the libraries specified by qmake. Investigating this:
..] $ sudo find / -name QApplication*
/usr/include/qt4/QtGui/QApplication
/usr/include/qt5/QtWidgets/QApplication
/home/drk/Canopy/appdata/canopy-1.0.1.1189.rh5-x86_64/include/QtGui/QApplication
Looking in the make file, the libraries supplied are (as can be seen from the compiler line):
INCPATH = -I/usr/share/qt5/mkspecs/linux-g++-64 -I. -I. -I/usr/include/qt5
-I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I.
Finally, looking at qmake:
..] $ qmake --version
QMake version 3.0
Using Qt version 5.0.1 in /usr/lib/x86_64-linux-gnu
So as you can see, qmake is assuming qt 5.0.1 despite the fact that I installed Qt4 and in my qt5 library directory hierarchy "QApplications" is located in /usr/include/qt5/QtWidgets and not in QtGui. However, qmake does not add QtWidgets/ to my include libraries.
I don't understand what has happened...can one not have qt4 and qt5 on one system at the same time?...does my qt5/qt5 installation appear corrupted?...how do I get qmake to use Qt4? Any suggestions would be greatly appreciated.
You can have both Qt 4 and 5 on the same system. However, there are little differences amongst them, and you're hitting one of those. In Qt 5, widgets now live in their own module, so you need to add
QT += widgets
to your .pro file and rerun qmake.
(And before you say that you don't see anything on screen: do not delete the label!)
See if there's a "qmake4", "qt4-qmake" or "qmake-qt4" command instead of just "qmake".
Also, why did you install Qt4 externally? Ubuntu offers it in its repositories. Just install it with Ubuntu's package manager. This way you can be sure it will be installed correctly. Qt Creator is also available in the repos.
I have Qt Creator installed on my Windows 7 machine and my target is an OMAP3 Embedded Linux board. I downloaded the target toolchain, Sourcery-G++ Lite for Windows, and also installed MinGW ( http://www.mingw.org/ ) on my Windows Machine. In QT Creator I added the CodeSourcery toolchain as a 'Manual' toolchain as shown in the image below. Then, I tried to build the demo Qt App 'analogclock' using this toolchain by editing 'Build Settings' under 'Projects' for the 'analogclock' demo app. But the toolchain is not available here under Build Settings as shown in the second image.
How can I achieve building this demo app, or any Qt app, from Qt Creator using the Code Sourcery Toolchain in the Build Options? I absolutely must use Windows to accomplish this ( cannot use Linux VM... ).
I believe it may have to do with building the Qt library for the target but am not sure if that is true or how to do that on Windows. I greatly appreciate your help and insight.
EDIT: New Information - need help configuring Qt Creator:
I've used the CodeSourcery toolchain to build the Qt 4.8 library with no error and I have the .so files in the /lib directory after following http://c2143.blogspot.com/?view=classic. Now I am trying to hook in the CodeSourcery compiler and built Qt 4.8 to Qt Creator so I can build an example app for the target board.
I read the following articles:
http://doc.qt.nokia.com/qtcreator-2.4/creator-project-qmake.html
http://doc.qt.nokia.com/qtcreator-2.4/creator-tool-chains.html
describing how to add a Qt version new toolchain to Qt Creator. Please see the images attached for how I've configured Qt Creator. I am using Qt Creator 2.4.1.
I'm getting an error without much information pasted below... Any thoughts on this or my configuration?
09:51:07: Running build steps for project analogclock...
09:51:07: Configuration unchanged, skipping qmake step.
09:51:07: Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
arm-none-linux-gnueabi-g++ -c -pipe -march=armv7-a -mtune=cortex-a8 -mthumb -mfpu=neon -mfloat-abi=softfp -Wa,-mimplicit-it=thumb -O2 -Wall -W -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I"..\qt-4.8-src\include\QtCore" -I"..\qt-4.8-src\include\QtNetwork" -I"..\qt-4.8-src\include\QtGui" -I"..\qt-4.8-src\include" -I"." -I"c:\QtSDK\Examples\4.7\widgets\analogclock" -I"." -I"..\qt-4.8-src\mkspecs\default" -o analogclock.obj c:\QtSDK\Examples\4.7\widgets\analogclock\analogclock.cpp
arm-none-linux-gnueabi-g++ -c -pipe -march=armv7-a -mtune=cortex-a8 -mthumb -mfpu=neon -mfloat-abi=softfp -Wa,-mimplicit-it=thumb -O2 -Wall -W -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I"..\qt-4.8-src\include\QtCore" -I"..\qt-4.8-src\include\QtNetwork" -I"..\qt-4.8-src\include\QtGui" -I"..\qt-4.8-src\include" -I"." -I"c:\QtSDK\Examples\4.7\widgets\analogclock" -I"." -I"..\qt-4.8-src\mkspecs\default" -o main.obj c:\QtSDK\Examples*\4.7\widgets\analogclock\main.cpp
C:\Users\pclass\Desktop\qt_creator_toolchain\qt-4.8-src\bin\moc.exe -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I"..\qt-4.8-src\include\QtCore" -I"..\qt-4.8-src\include\QtNetwork" -I"..\qt-4.8-src\include\QtGui" -I"..\qt-4.8-src\include" -I"." -I"c:\QtSDK\Examples\4.7\widgets\analogclock" -I"." -I"..\qt-4.8-src\mkspecs\default" c:\QtSDK\Examples\4.7\widgets\analogclock\analogclock.h -o moc_analogclock.cpp
mingw32-make.exe: *** [moc_analogclock.cpp] Error -1073741515
09:51:09: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project analogclock (target: Desktop)
When executing build step 'Make'
You need the Qt library for the target first. You can build it with CodeSourcery toolchain. Then, some tools(qmake, moc...) and library are available.
I added mingw to the path and then did a build and it succeeded. If I do a ‘file’ command on the example it gives me the following, which looks promising. Now to try it on the board.
$ file analogclock
analogclock: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped