PDA

View Full Version : Qt installation under Linux



mickey
18th July 2016, 20:59
Hello,
I'm trying to compile this simple program at command line:


#include <QApplication>
#include <QWidget>

int main(int argc, char* argv[]) {

QApplication app(argc, argv);
QWidget w;
w.resize(640, 480);
w.show();
return app.exec();
}

I typed:


qmake -project //ok
qmake //ok
make //errors

'make' gives me a lot of errors. I suppose they depend from 'bad setting' of qt or other things under LInux.
Just to give an idea of the problem:


gcc -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -I. -o main.o main.c
In file included from /usr/include/QtCore/qobjectdefs.h:45:0,
from /usr/include/QtCore/qobject.h:47,
from /usr/include/QtCore/qcoreapplication.h:45,
from /usr/include/QtGui/qapplication.h:45,
from /usr/include/QtGui/QApplication:1,
from main.c:1:
/usr/include/QtCore/qnamespace.h: In function ‘QT_MODULE’:
/usr/include/QtCore/qnamespace.h:54:1: error: unknown type name ‘namespace’
namespace
^
/usr/include/QtCore/qnamespace.h:58:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or __attribute__’ before ‘{’ token
Qt {
^
/usr/include/QtCore/qnamespace.h:1799:1: error: expected declaration specifiers before ‘Q_DECLARE_OPERATORS_FOR_FLAGS’
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::MouseButtons)
^
/usr/include/QtCore/qnamespace.h:1820:1: error: unknown type name ‘class’
class Q_CORE_EXPORT QInternal {
^
/usr/include/QtCore/qnamespace.h:1820:21: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QInternal’
class Q_CORE_EXPORT QInternal {
^
/usr/include/QtCore/qnamespace.h:1875:2: error: expected declaration specifiers before ‘;’ token
};
^
In file included from /usr/include/QtCore/qobject.h:47:0,
from /usr/include/QtCore/qcoreapplication.h:45,
from /usr/include/QtGui/qapplication.h:45,
from /usr/include/QtGui/QApplication:1,
from main.c:1:

[.................................................. .................................................. ................so on.......]


Does anybody have an idea about the problem?

Hello,
I'm trying to compile this simple program at command line:


#include <QApplication>
#include <QWidget>

int main(int argc, char* argv[]) {

QApplication app(argc, argv);
QWidget w;
w.resize(640, 480);
w.show();
return app.exec();
}

I typed:


qmake -project //ok
qmake //ok
make //errors

'make' gives me a lot of errors. I suppose they depend from 'bad setting' of qt or other things under LInux.
Just to give an idea of the problem:


gcc -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -I. -o main.o main.c
In file included from /usr/include/QtCore/qobjectdefs.h:45:0,
from /usr/include/QtCore/qobject.h:47,
from /usr/include/QtCore/qcoreapplication.h:45,
from /usr/include/QtGui/qapplication.h:45,
from /usr/include/QtGui/QApplication:1,
from main.c:1:
/usr/include/QtCore/qnamespace.h: In function ‘QT_MODULE’:
/usr/include/QtCore/qnamespace.h:54:1: error: unknown type name ‘namespace’
namespace
^
/usr/include/QtCore/qnamespace.h:58:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or __attribute__’ before ‘{’ token
Qt {
^
/usr/include/QtCore/qnamespace.h:1799:1: error: expected declaration specifiers before ‘Q_DECLARE_OPERATORS_FOR_FLAGS’
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::MouseButtons)
^
/usr/include/QtCore/qnamespace.h:1820:1: error: unknown type name ‘class’
class Q_CORE_EXPORT QInternal {
^
/usr/include/QtCore/qnamespace.h:1820:21: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QInternal’
class Q_CORE_EXPORT QInternal {
^
/usr/include/QtCore/qnamespace.h:1875:2: error: expected declaration specifiers before ‘;’ token
};
^
In file included from /usr/include/QtCore/qobject.h:47:0,
from /usr/include/QtCore/qcoreapplication.h:45,
from /usr/include/QtGui/qapplication.h:45,
from /usr/include/QtGui/QApplication:1,
from main.c:1:

[.................................................. .................................................. ................so on.......]


Does anybody have an idea about the problem?

Added after 1 34 minutes:

Hello again,

I found out to have installed also qmake-qt5. So using it I got a just an error:


make
gcc -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -O2 -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtGui -isystem /usr/include/qt5/QtCore -I. -I/usr/lib64/qt5/mkspecs/linux-g++ -o main.o main.c
main.c:1:24: fatal error: QApplication: No such file or directory
#include <QApplication>
^
compilation terminated.
make: *** [main.o] Error 1


What do you think? Anything is improving?

anda_skoa
18th July 2016, 21:57
You forgot to post your .pro file.

Most like it is missing the QT configuration option for widget usage.


QT += widgets


Cheers,
_

P.S.: your application should also have compiled with Qt4

mickey
19th July 2016, 10:37
Hello,
the problem persists; here the output:


qmake-qt4 -project
# qmake-qt4
# make

/usr/bin/qmake-qt4 -o Makefile ex1.pro
gcc -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -I. -o main.o main.c
In file included from /usr/include/QtCore/qobjectdefs.h:45:0,
from /usr/include/QtCore/qobject.h:47,
from /usr/include/QtCore/qcoreapplication.h:45,
from /usr/include/QtGui/qapplication.h:45,
from /usr/include/QtGui/QApplication:1,
from main.c:1:
/usr/include/QtCore/qnamespace.h: In function ‘QT_MODULE’:
/usr/include/QtCore/qnamespace.h:54:1: error: unknown type name ‘namespace’
namespace
^
/usr/include/QtCore/qnamespace.h:58:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
Qt {
^
/usr/include/QtCore/qnamespace.h:1799:1: error: expected declaration specifiers before ‘Q_DECLARE_OPERATORS_FOR_FLAGS’

[..............................................so on................................................ .................................]




################################################## ####################
# Automatically generated by qmake (2.01a) Tue Jul 19 11:24:02 2016
################################################## ####################

TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
QT += widgets

# Input
SOURCES += main.c



#include <QApplication>
#include <QWidget>

int main(int argc, char* argv[]) {

QApplication app(argc, argv);
QWidget w;
w.resize(640, 480);
w.show();
return app.exec();
}

Any further idea?

anda_skoa
19th July 2016, 10:54
That .pro file is for Qt5 now ("widgets" was implied in Qt4 and did not exist as a separate module).

However, you main problem is that you called your C++ file "main.c".
So the build system treats it as a C file and tries to compile with the C compiler. which, obviously, doesn't understand C++.

Cheers,
_