在Linux下编译Qt5程序
代码
#include <QtGui/QApplication>
#include <QtGui/QLabel>
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
QLabel *label=new QLabel("Hello QT!");
label->show();
return app.exec();
}
Makefile 文件
#############################################################################
# Makefile for building: testQT
# Generated by qmake (1.07a) (Qt 3.3.8b) on: Wed Nov 27 12:16:07 2013
# Project: testQT.pro
# Template: app
# Command: $(QMAKE) -o Makefile testQT.pro
#############################################################################
####### Compiler, tools and options
CC = gcc
CXX = g++
LEX = flex
YACC = yacc
CFLAGS = -pipe -Wall -W -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing -DQT_NO_DEBUG
CXXFLAGS = -pipe -Wall -W -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing -DQT_NO_DEBUG
LEXFLAGS =
YACCFLAGS= -d
INCPATH = -I/usr/lib64/qt-3.3/mkspecs/default -I. -I. -I$(QTDIR)/include
LINK = g++
LFLAGS =
LIBS = $(SUBLIBS) -L$(QTDIR)/lib -lqt-mt -lXext -lX11 -lm
AR = ar cqs
RANLIB =
MOC = $(QTDIR)/bin/moc
UIC = $(QTDIR)/bin/uic
QMAKE = qmake
TAR = tar -cf
GZIP = gzip -9f
COPY = cp -f
COPY_FILE= $(COPY)
COPY_DIR = $(COPY) -r
INSTALL_FILE= $(COPY_FILE)
INSTALL_DIR = $(COPY_DIR)
DEL_FILE = rm -f
SYMLINK = ln -sf
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
####### Output directory
OBJECTS_DIR = ./
####### Files
HEADERS =
SOURCES = main.cpp
OBJECTS = main.o
FORMS =
UICDECLS =
UICIMPLS =
SRCMOC =
OBJMOC =
DIST = testQT.pro
QMAKE_TARGET = testQT
DESTDIR =
TARGET = testQT
first: all
####### Implicit rules
.SUFFIXES: .c .o .cpp .cc .cxx .C
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
####### Build rules
all: Makefile $(TARGET)
$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(OBJCOMP) $(LIBS)
mocables: $(SRCMOC)
uicables: $(UICDECLS) $(UICIMPLS)
$(MOC):
( cd $(QTDIR)/src/moc && $(MAKE) )
Makefile: testQT.pro /usr/lib64/qt-3.3/mkspecs/default/qmake.conf
$(QMAKE) -o Makefile testQT.pro
qmake:
@$(QMAKE) -o Makefile testQT.pro
dist:
@mkdir -p .tmp/testQT && $(COPY_FILE) --parents $(SOURCES) $(HEADERS) $(FORMS) $(DIST) .tmp/testQT/ && ( cd `dirname .tmp/testQT` && $(TAR) testQT.tar testQT && $(GZIP) testQT.tar ) && $(MOVE) `dirname .tmp/testQT`/testQT.tar.gz . && $(DEL_FILE) -r .tmp/testQT
mocclean:
uiclean:
yaccclean:
lexclean:
clean:
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Sub-libraries
distclean: clean
-$(DEL_FILE) $(TARGET) $(TARGET)
FORCE:
####### Compile
main.o: main.cpp
####### Install
install:
uninstall:
若用makefile文件编译,qt-mt版本为 libqt-mt.so.3.3.8
报错