qmake with Jenkins - c++

I am trying to make Jenkins do the compile and build for me whenever I push commit to Git. I have a helloworld app created in Qt Creator. It does compile and build in Qt Creator, it does show on my phone, but it doesn't want to compile and build with Jenkins.
I am using the same shell commands which QtC used:
qmake helloworld.pro -r -spec android-g++;
make;
The console output is:
+ qmake helloworld.pro -r -spec android-g++
+ make
/home/ndk/toolchains/arm-linux-androideabi-4.9-/prebuilt/bin/arm-linux-androideabi-g++ -c -pipe -std=c++11 -O2 -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -mthumb -Wall -Wno-psabi -W -I/usr/share/qt4/mkspecs/android-g++ -I. -I. -I/home/ndk/sources/cxx-stl/gnu-libstdc++//include -I/home/ndk/sources/cxx-stl/gnu-libstdc++//libs//include -I/home/ndk/platforms//arch-arm//usr/include -o main.o main.cpp
In file included from main.cpp:1:0:
mainwindow.h:4:23: fatal error: QMainWindow: No such file or directory
#include <QMainWindow>
^
compilation terminated.
Makefile:187: recipe for target 'main.o' failed
make: *** [main.o] Error 1
My helloworld.pro:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = helloworld
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
CONFIG += mobility
MOBILITY =
main.cpp
#include "mainwindow.h"
#include <QMainWindow>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
EDIT/UPDATE:
So far, I have tried to specify the full path to qmake, to be sure that I use Qt's qmake.
/home/qt/5.7/android_armv7/bin/qmake helloworld.pro -r -spec android-g++;
make;
The output is:
/home/qt/5.7/android_armv7/bin/uic mainwindow.ui -o ui_mainwindow.h
/home/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -c -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -DANDROID -Wa,--noexecstack -fno-builtin-memmove -std=c++11 -O2 -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -mthumb -Wall -Wno-psabi -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../qt/5.7/android_armv7/include -I../../qt/5.7/android_armv7/include/QtWidgets -I../../qt/5.7/android_armv7/include/QtGui -I../../qt/5.7/android_armv7/include/QtCore -I. -I. -I../../ndk/sources/cxx-stl/gnu-libstdc++/4.9/include -I../../ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -I../../ndk/platforms/android-9/arch-arm/usr/include -I../../qt/5.7/android_armv7/mkspecs/android-g++ -o main.o main.cpp
/home/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -c -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -DANDROID -Wa,--noexecstack -fno-builtin-memmove -std=c++11 -O2 -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -mthumb -Wall -Wno-psabi -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../qt/5.7/android_armv7/include -I../../qt/5.7/android_armv7/include/QtWidgets -I../../qt/5.7/android_armv7/include/QtGui -I../../qt/5.7/android_armv7/include/QtCore -I. -I. -I../../ndk/sources/cxx-stl/gnu-libstdc++/4.9/include -I../../ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -I../../ndk/platforms/android-9/arch-arm/usr/include -I../../qt/5.7/android_armv7/mkspecs/android-g++ -o mainwindow.o mainwindow.cpp
mainwindow.cpp:3:25: fatal error: QtGui/QAction: No such file or directory
#include <QtGui/QAction>
^
compilation terminated.
Makefile:1780: recipe for target 'mainwindow.o' failed
make: *** [mainwindow.o] Error 1

Most likely your jenkins setup uses the wrong qmake. There's a 1:1 mapping between a Qt installation and its qmake. So, your install of Qt for android will have its own qmake that you must refer to by full path! Qt Creator sets up the path so that this happens automatically, Jenkins doesn't - and it shouldn't anyway.
When building for any particular Qt version, you only need to invoke its qmake explicitly. From then onwards, as long as the proper compiler is in the path, things will happen as they should and you don't ever need to refer to that Qt version manually again. The makefiles will all refer to Qt libraries, headers and tools from that Qt install.
You also don't need the -spec argument. Each Qt installation is compiled for a particular mkspec, so qmake itself knows exactly what the spec is. I have no idea why QtCreator gives that argument, it doesn't make much sense.

The only Qt header path that's in your commandline is the one for the mkspec. I would blame the server's Qt installation for this.
Ensure Qt for Android is properly installed on the server, and that it is its qmake you are calling.

Related

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

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.

qmake doesn't invoke uic

I'm aware that there is a couple of questions asked online on similar issues but unfortunately none of them helped me solving this relatively simple-looking one, as the title suggests.
I set up a minimal Qt project in which the problem occurs:
├── main.cpp
├── mainwindow.ui
└── qt.pro
main.cpp:
#include <QtWidgets/QtWidgets>
#include "ui_mainwindow.h"
int main () {
return 0;
}
qt.pro:
TEMPLATE = app
TARGET = qt-qmake-uic-problem
INCLUDEPATH += .
# Input
FORMS += mainwindow.ui
SOURCES += main.cpp
The file mainwindow.ui is the default MainWindow Form provided by Qt Creator.
Now if I run
qmake qt.pro
then a Makefile is created causing this error when make gets executed:
[developer#kdb qt-qmake-uic-problem]$ make
g++ -c -pipe -O2 -march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/qt -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -I. -I/usr/lib/qt/mkspecs/linux-g++ -o main.o main.cpp
main.cpp:2:28: fatal error: ui_mainwindow.ui: No such file or directory
#include "ui_mainwindow.h"
^
compilation terminated.
make: *** [Makefile:298: main.o] Error 1
According to my best knowledge ui_mainwindow.h must be generated either by qmake or by the Makefile - not by myself invoking uic manually. I must note that something similar happens with moc as well and doing my research I haven't found an explanation neither in the documentation nor in similar issues, although it would be strange if this installation of qmake were broken - I'm running Arch Linux and got Qt SDK from the default repository.
Thank you very much for your help in advice!
Assuming you are using QT-5:
If you want to use UI elements linke a QMainWindow or other QT widgets, you need to enable widgets generally in your project configuration:
QT += widgets
This then activates the processing of the FORMS content like mainwindow.ui in your example, and causes that your code gets linked with the correct libraries.
See also here: http://doc.qt.io/qt-5/qtwidgets-index.html

Travis CI QT not building

So I wanted to use travis for this project today. Sadly it failed with this error:
$ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt5/mkspecs/linux-g++-64 -I. -I. -I/usr/include/qt5 -I/usr/include/qt5/QtNetwork -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o downloadmanager.o downloadmanager.cpp
In file included from downloadmanager.h:11:0,
from downloadmanager.cpp:1:
mainwindow.h:4:23: fatal error: QMainWindow: No such file or directory
compilation terminated.
make: *** [downloadmanager.o] Error 1
The command "make" exited with 2.
Here is the full log.
Note I first had problems with it not recognizing the Network module file (e.g. QNetworkAccessManager). I fixed this by executing QMake with "QT += network". Now it cannot find the GUI files (e.g. QMessageBox) but adding "QT += network gui" did not do the trick.
You need to add widgets to get classes such as QMessageBox and QMainWindow:
QT += widgets network gui
For future reference, please consult the Qt 5 documentation. The page for each class indicates what must be added to your qmake for that class (right at the top of the page). See, for example, the page for QMessageBox.

Problem building stripped down version of Qt 4.6.2

I'm trying to build a smaller version of Qt, I used the following configuration options:
./configure -qt-sql-mysql -no-qt3support -no-audio-backend -no-phonon -no-phonon-backend -no-opengl -no-script -no-scripttools -no-javascript-jit -no-webkit -no-svg -no-multimedia -fast
After executing make, I eventually run into the following error:
make[3]: Entering directory `/opt/qtsdk-2010.02/qt/tools/assistant/tools'
cd assistant/ && make -f Makefile
make[4]: Entering directory `/opt/qtsdk-2010.02/qt/tools/assistant/tools/assistant'
g++ -c -pipe -g -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_SQL_LIB -DQT_XML_LIB -DQT_GUI_LIB
-DQT_NETWORK_LIB -DQT_CORE_LIB -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_SHARED
-I../../../../mkspecs/linux-g++ -I. -I../../../../include/QtCore
-I../../../../include/QtNetwork -I../../../../include/QtGui -I../../../../include/QtXml
-I../../../../include/QtSql -I../../../../include -I../../../../include/QtHelp
-I../../../shared/fontpanel -I.moc/release-shared -I.uic/release-shared
-o .obj/release-shared/helpviewer.o helpviewer.cpp
In file included from helpviewer.cpp:42:
helpviewer.h:51:20: error: QWebView: No such file or directory
Any pointers on what is wrong here?
It is trying to build the Assistant (that is the tool you us to view Qt documentation) tool, the Assistant needs webkit. If you don't need Assistant in your application when you are distributing it, just exclude it from the build