现在的位置: 首页 > 综合 > 正文

Qt_FirstRunningApp

2013年05月27日 ⁄ 综合 ⁄ 共 15972字 ⁄ 字号 评论关闭

 

 

Create a makefile project in visual studio 2005. Fill "nmake debug/release" and "nmake clean" in the build command line and clean command line fields and leave the rebuild command line until later.

 

Go to Project-Properties-Configuration Properties page. Fill the Rebuild All Command Line with

qmake -project

qmake

nmake clean

nmake debug/release.

( See A* )

 

Rebuild your project to have the .pro, makefile, makefile.debug and makefile.release generated. Then go back to the above and remove the first two lines:

qmake -project

qmake.

This prevents the makefile from being overwritten each time we rebuild our project.

 

This should be enough for a hello world application, but for more advanced application, say, an opengl application, we need to modify the makefile manually.

For example, let us try to build the hellogl example. Follow the above steps where we end up with compiling errors blah blah blah. The error is caused by our failure to link against the modules needed for opengl.

 

To make
the example build, do the following ( suppose we are dealing with the release version ).

Add -DQT_OPENGL_LIB to DEFINES.

Add -I"D:/Qt/4.5.3/include/QtOpengl" to the INCPATH.

Add D:/Qt/4.5.3/lib/QtOpengl4.lib and opengl32.lib to LIBS.

We should compile and link the code with success now.

 

Make sure to link against D:/Qt/4.5.3/lib/QtOpengld4.lib when dealing with debug version.

 

 

 

 

A*

For a better understanding of what the four lines do during a rebuild of the project, we can compare the results of a few different command combinations.

Suppose the current directory is called Temp.

 

NoFile: There is no file under the current directory.

MainCpp: There is a main.cpp under the current directory.

 

 

Case One: NoFile

 

The command sequence:

 

qmake -project

 

would create a Temp.pro with the following content:

{

 

######################################################################

# Automatically generated by qmake (2.01a) ??? ?? 3 12:20:38 2010

######################################################################


TEMPLATE = subdirs


# Directories

 

}

 

The command sequence:

 

qmake

 

would do nothing but print out qmake's help text.

 

The command sequence:

 

qmake -project

qmake

 

would create a Temp.pro as in the first case, and then a Makefile containing the following:

{

 

#############################################################################

# Makefile for building: temp

# Generated by qmake (2.01a) (Qt 4.5.3) on: ??? ?? 3 15:56:50 2010

# Project:  temp.pro

# Template: subdirs

# Command: d:/Qt/4.5.3/bin/qmake.exe -win32 -o Makefile temp.pro

#############################################################################


first: make_default

MAKEFILE      = Makefile

QMAKE         = d:/Qt/4.5.3/bin/qmake.exe

DEL_FILE      = del

CHK_DIR_EXISTS= if not exist

MKDIR         = mkdir

COPY          = copy /y

COPY_FILE     = $(COPY)

COPY_DIR      = xcopy /s /q /y /i

INSTALL_FILE  = $(COPY_FILE)

INSTALL_PROGRAM = $(COPY_FILE)

INSTALL_DIR   = $(COPY_DIR)

DEL_FILE      = del

SYMLINK       = 

DEL_DIR       = rmdir

MOVE          = move

CHK_DIR_EXISTS= if not exist

MKDIR         = mkdir

SUBTARGETS    = 


Makefile: temp.pro  d:/Qt/4.5.3/mkspecs/win32-msvc2005/qmake.conf d:/Qt/4.5.3/mkspecs/qconfig.pri /

d:/Qt/4.5.3/mkspecs/features/qt_functions.prf /

d:/Qt/4.5.3/mkspecs/features/qt_config.prf /

d:/Qt/4.5.3/mkspecs/features/exclusive_builds.prf /

d:/Qt/4.5.3/mkspecs/features/default_pre.prf /

d:/Qt/4.5.3/mkspecs/features/win32/default_pre.prf /

d:/Qt/4.5.3/mkspecs/features/debug.prf /

d:/Qt/4.5.3/mkspecs/features/debug_and_release.prf /

d:/Qt/4.5.3/mkspecs/features/default_post.prf /

d:/Qt/4.5.3/mkspecs/features/win32/default_post.prf /

d:/Qt/4.5.3/mkspecs/features/win32/rtti.prf /

d:/Qt/4.5.3/mkspecs/features/win32/exceptions.prf /

d:/Qt/4.5.3/mkspecs/features/shared.prf /

d:/Qt/4.5.3/mkspecs/features/win32/embed_manifest_exe.prf /

d:/Qt/4.5.3/mkspecs/features/win32/embed_manifest_dll.prf /

d:/Qt/4.5.3/mkspecs/features/warn_on.prf /

d:/Qt/4.5.3/mkspecs/features/qt.prf /

d:/Qt/4.5.3/mkspecs/features/win32/thread.prf /

d:/Qt/4.5.3/mkspecs/features/moc.prf /

d:/Qt/4.5.3/mkspecs/features/win32/windows.prf /

d:/Qt/4.5.3/mkspecs/features/win32/stl_off.prf /

d:/Qt/4.5.3/mkspecs/features/resources.prf /

d:/Qt/4.5.3/mkspecs/features/uic.prf /

d:/Qt/4.5.3/mkspecs/features/yacc.prf /

d:/Qt/4.5.3/mkspecs/features/lex.prf /

d:/Qt/4.5.3/mkspecs/features/include_source_dir.prf

$(

QMAKE) -win32 -o Makefile temp.pro

d:/Qt/4.5.3/mkspecs/qconfig.pri:

d:/Qt/4.5.3/mkspecs/features/qt_functions.prf:

d:/Qt/4.5.3/mkspecs/features/qt_config.prf:

d:/Qt/4.5.3/mkspecs/features/exclusive_builds.prf:

d:/Qt/4.5.3/mkspecs/features/default_pre.prf:

d:/Qt/4.5.3/mkspecs/features/win32/default_pre.prf:

d:/Qt/4.5.3/mkspecs/features/debug.prf:

d:/Qt/4.5.3/mkspecs/features/debug_and_release.prf:

d:/Qt/4.5.3/mkspecs/features/default_post.prf:

d:/Qt/4.5.3/mkspecs/features/win32/default_post.prf:

d:/Qt/4.5.3/mkspecs/features/win32/rtti.prf:

d:/Qt/4.5.3/mkspecs/features/win32/exceptions.prf:

d:/Qt/4.5.3/mkspecs/features/shared.prf:

d:/Qt/4.5.3/mkspecs/features/win32/embed_manifest_exe.prf:

d:/Qt/4.5.3/mkspecs/features/win32/embed_manifest_dll.prf:

d:/Qt/4.5.3/mkspecs/features/warn_on.prf:

d:/Qt/4.5.3/mkspecs/features/qt.prf:

d:/Qt/4.5.3/mkspecs/features/win32/thread.prf:

d:/Qt/4.5.3/mkspecs/features/moc.prf:

d:/Qt/4.5.3/mkspecs/features/win32/windows.prf:

d:/Qt/4.5.3/mkspecs/features/win32/stl_off.prf:

d:/Qt/4.5.3/mkspecs/features/resources.prf:

d:/Qt/4.5.3/mkspecs/features/uic.prf:

d:/Qt/4.5.3/mkspecs/features/yacc.prf:

d:/Qt/4.5.3/mkspecs/features/lex.prf:

d:/Qt/4.5.3/mkspecs/features/include_source_dir.prf:

qmake: qmake_all FORCE

@$(QMAKE) -win32 -o Makefile temp.pro


qmake_all: FORCE


make_default: FORCE

make_first: FORCE

all: FORCE

clean: FORCE

distclean: FORCE

-$(DEL_FILE) Makefile

install_subtargets: FORCE

uninstall_subtargets: FORCE


debug:


release:


mocclean: compiler_moc_header_clean compiler_moc_source_clean


mocables: compiler_moc_header_make_all compiler_moc_source_make_all

install: install_subtargets  FORCE


uninstall:  uninstall_subtargets FORCE


FORCE:

}

 

Case Two: MainCpp

 

The command sequence:

 

qmake -project

 

would create a Temp.pro with the following content:

{

 

######################################################################

# Automatically generated by qmake (2.01a) ??? ?? 3 15:58:35 2010

######################################################################


TEMPLATE = app

TARGET = 

DEPENDPATH += .

INCLUDEPATH += .


# Input

SOURCES += main.cpp

}

 

The command sequence:

 

qmake

 

would still do nothing but print out qmake's help text.

 

The command sequence:

 

qmake -project

qmake

 

would create a Temp.pro as the first sequence, and then the following:

 

- A Makefile, Makefile.Debug and Makefile.Release

- An empty debug folder and an empty release folder.

 

The content of Makefile and Makefile.Debug are shown below:

 

Makefile

{

#############################################################################

# Makefile for building: temp

# Generated by qmake (2.01a) (Qt 4.5.3) on: ??? ?? 3 16:02:03 2010

# Project:  temp.pro

# Template: app

# Command: d:/Qt/4.5.3/bin/qmake.exe -win32 -o Makefile temp.pro

#############################################################################

 

first: debug

install: debug-install

uninstall: debug-uninstall

MAKEFILE      = Makefile

QMAKE         = d:/Qt/4.5.3/bin/qmake.exe

DEL_FILE      = del

CHK_DIR_EXISTS= if not exist

MKDIR         = mkdir

COPY          = copy /y

COPY_FILE     = $(COPY)

COPY_DIR      = xcopy /s /q /y /i

INSTALL_FILE  = $(COPY_FILE)

INSTALL_PROGRAM = $(COPY_FILE)

INSTALL_DIR   = $(COPY_DIR)

DEL_FILE      = del

SYMLINK       = 

DEL_DIR       = rmdir

MOVE          = move

CHK_DIR_EXISTS= if not exist

MKDIR         = mkdir

SUBTARGETS    =  /

debug /

release

 

debug: $(MAKEFILE).Debug FORCE

$(MAKE) -f $(MAKEFILE).Debug

debug-make_default: $(MAKEFILE).Debug FORCE

$(MAKE) -f $(MAKEFILE).Debug 

debug-make_first: $(MAKEFILE).Debug FORCE

$(MAKE) -f $(MAKEFILE).Debug first

debug-all: $(MAKEFILE).Debug FORCE

$(MAKE) -f $(MAKEFILE).Debug all

debug-clean: $(MAKEFILE).Debug FORCE

$(MAKE) -f $(MAKEFILE).Debug clean

debug-distclean: $(MAKEFILE).Debug FORCE

$(MAKE) -f $(MAKEFILE).Debug distclean

debug-install: $(MAKEFILE).Debug FORCE

$(MAKE) -f $(MAKEFILE).Debug install

debug-uninstall: $(MAKEFILE).Debug FORCE

$(MAKE) -f $(MAKEFILE).Debug uninstall

release: $(MAKEFILE).Release FORCE

$(MAKE) -f $(MAKEFILE).Release

release-make_default: $(MAKEFILE).Release FORCE

$(MAKE) -f $(MAKEFILE).Release 

release-make_first: $(MAKEFILE).Release FORCE

$(MAKE) -f $(MAKEFILE).Release first

release-all: $(MAKEFILE).Release FORCE

$(MAKE) -f $(MAKEFILE).Release all

release-clean: $(MAKEFILE).Release FORCE

$(MAKE) -f $(MAKEFILE).Release clean

release-distclean: $(MAKEFILE).Release FORCE

$(MAKE) -f $(MAKEFILE).Release distclean

release-install: $(MAKEFILE).Release FORCE

$(MAKE) -f $(MAKEFILE).Release install

release-uninstall: $(MAKEFILE).Release FORCE

$(MAKE) -f $(MAKEFILE).Release uninstall

 

Makefile: temp.pro  d:/Qt/4.5.3/mkspecs/win32-msvc2005/qmake.conf d:/Qt/4.5.3/mkspecs/qconfig.pri /

d:/Qt/4.5.3/mkspecs/features/qt_functions.prf /

d:/Qt/4.5.3/mkspecs/features/qt_config.prf /

d:/Qt/4.5.3/mkspecs/features/exclusive_builds.prf /

d:/Qt/4.5.3/mkspecs/features/default_pre.prf /

d:/Qt/4.5.3/mkspecs/features/win32/default_pre.prf /

d:/Qt/4.5.3/mkspecs/features/debug.prf /

d:/Qt/4.5.3/mkspecs/features/debug_and_release.prf /

d:/Qt/4.5.3/mkspecs/features/default_post.prf /

d:/Qt/4.5.3/mkspecs/features/win32/default_post.prf /

d:/Qt/4.5.3/mkspecs/features/win32/rtti.prf /

d:/Qt/4.5.3/mkspecs/features/win32/exceptions.prf /

d:/Qt/4.5.3/mkspecs/features/shared.prf /

d:/Qt/4.5.3/mkspecs/features/win32/embed_manifest_exe.prf /

d:/Qt/4.5.3/mkspecs/features/win32/embed_manifest_dll.prf /

d:/Qt/4.5.3/mkspecs/features/warn_on.prf /

d:/Qt/4.5.3/mkspecs/features/qt.prf /

d:/Qt/4.5.3/mkspecs/features/win32/thread.prf /

d:/Qt/4.5.3/mkspecs/features/moc.prf /

d:/Qt/4.5.3/mkspecs/features/win32/windows.prf /

d:/Qt/4.5.3/mkspecs/features/win32/stl_off.prf /

d:/Qt/4.5.3/mkspecs/features/resources.prf /

d:/Qt/4.5.3/mkspecs/features/uic.prf /

d:/Qt/4.5.3/mkspecs/features/yacc.prf /

d:/Qt/4.5.3/mkspecs/features/lex.prf /

d:/Qt/4.5.3/mkspecs/features/include_source_dir.prf /

d:/Qt/4.5.3/lib/qtmaind.prl

$(QMAKE) -win32 -o Makefile temp.pro

d:/Qt/4.5.3/mkspecs/qconfig.pri:

d:/Qt/4.5.3/mkspecs/features/qt_functions.prf:

d:/Qt/4.5.3/mkspecs/features/qt_config.prf:

d:/Qt/4.5.3/mkspecs/features/exclusive_builds.prf:

d:/Qt/4.5.3/mkspecs/features/default_pre.prf:

d:/Qt/4.5.3/mkspecs/features/win32/default_pre.prf:

d:/Qt/4.5.3/mkspecs/features/debug.prf:

d:/Qt/4.5.3/mkspecs/features/debug_and_release.prf:

d:/Qt/4.5.3/mkspecs/features/default_post.prf:

d:/Qt/4.5.3/mkspecs/features/win32/default_post.prf:

d:/Qt/4.5.3/mkspecs/features/win32/rtti.prf:

d:/Qt/4.5.3/mkspecs/features/win32/exceptions.prf:

d:/Qt/4.5.3/mkspecs/features/shared.prf:

d:/Qt/4.5.3/mkspecs/features/win32/embed_manifest_exe.prf:

d:/Qt/4.5.3/mkspecs/features/win32/embed_manifest_dll.prf:

d:/Qt/4.5.3/mkspecs/features/warn_on.prf:

d:/Qt/4.5.3/mkspecs/features/qt.prf:

d:/Qt/4.5.3/mkspecs/features/win32/thread.prf:

d:/Qt/4.5.3/mkspecs/features/moc.prf:

d:/Qt/4.5.3/mkspecs/features/win32/windows.prf:

d:/Qt/4.5.3/mkspecs/features/win32/stl_off.prf:

d:/Qt/4.5.3/mkspecs/features/resources.prf:

d:/Qt/4.5.3/mkspecs/features/uic.prf:

d:/Qt/4.5.3/mkspecs/features/yacc.prf:

d:/Qt/4.5.3/mkspecs/features/lex.prf:

d:/Qt/4.5.3/mkspecs/features/include_source_dir.prf:

d:/Qt/4.5.3/lib/qtmaind.prl:

qmake: qmake_all FORCE

@$(QMAKE) -win32 -o Makefile temp.pro

 

qmake_all: FORCE

 

make_default: debug-make_default release-make_default FORCE

make_first: debug-make_first release-make_first FORCE

all: debug-all release-all FORCE

clean: debug-clean release-clean FORCE

-$(DEL_FILE) "./temp.intermediate.manifest"

-$(DEL_FILE) temp.exp

-$(DEL_FILE) temp.pdb

-$(DEL_FILE) temp.ilk

-$(DEL_FILE) vc*.pdb

-$(DEL_FILE) vc*.idb

distclean: debug-distclean release-distclean FORCE

-$(DEL_FILE) Makefile

 

debug-mocclean: $(MAKEFILE).Debug

$(MAKE) -f $(MAKEFILE).Debug mocclean

release-mocclean: $(MAKEFILE).Release

$(MAKE) -f $(MAKEFILE).Release mocclean

mocclean: debug-mocclean release-mocclean

 

debug-mocables: $(MAKEFILE).Debug

$(MAKE) -f $(MAKEFILE).Debug mocables

release-mocables: $(MAKEFILE).Release

$(MAKE) -f $(MAKEFILE).Release mocables

mocables: debug-mocables release-mocables

FORCE:

 

$(MAKEFILE).Debug: Makefile

$(MAKEFILE).Release: Makefile

}

 

Makefile.Debug

{

#############################################################################

# Makefile for building: temp

# Generated by qmake (2.01a) (Qt 4.5.3) on: ??? ?? 3 16:02:03 2010

# Project:  temp.pro

# Template: app

#############################################################################

 

####### Compiler, tools and options

 

CC            = cl

CXX           = cl

DEFINES       = -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT

CFLAGS        = -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -W3 $(DEFINES)

CXXFLAGS      = -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 $(DEFINES)

INCPATH       = -I"d:/Qt/4.5.3/include/QtCore" -I"d:/Qt/4.5.3/include/QtGui" -I"d:/Qt/4.5.3/include" -I"." -I"d:/Qt/4.5.3/include/ActiveQt" -I"debug" -I"d:/Qt/4.5.3/mkspecs/win32-msvc2005"

LINK          = link

LFLAGS        = /LIBPATH:"d:/Qt/4.5.3/lib" /NOLOGO /DEBUG /MANIFEST /MANIFESTFILE:"debug/temp.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'"

LIBS          = d:/Qt/4.5.3/lib/qtmaind.lib d:/Qt/4.5.3/lib/QtGuid4.lib d:/Qt/4.5.3/lib/QtCored4.lib

QMAKE         = d:/Qt/4.5.3/bin/qmake.exe

IDC           = d:/Qt/4.5.3/bin/idc.exe

IDL           = midl

ZIP           = zip -r -9

DEF_FILE      = 

RES_FILE      = 

COPY          = copy /y

COPY_FILE     = $(COPY)

COPY_DIR      = xcopy /s /q /y /i

DEL_FILE      = del

DEL_DIR       = rmdir

MOVE          = move

CHK_DIR_EXISTS= if not exist

MKDIR         = mkdir

INSTALL_FILE    = $(COPY_FILE)

INSTALL_PROGRAM = $(COPY_FILE)

INSTALL_DIR     = $(COPY_DIR)

 

####### Output directory

OBJECTS_DIR   = debug

 

####### Files

SOURCES       = main.cpp 

OBJECTS       = debug/main.obj

DIST          = 

QMAKE_TARGET  = temp

DESTDIR        = debug/ #avoid trailing-slash linebreak

TARGET         = temp.exe

DESTDIR_TARGET = debug/temp.exe

 

####### Implicit rules

.SUFFIXES: .c .cpp .cc .cxx

 

{.}.cpp{debug/}.obj::

$(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug/ @<<

$<

<<

 

{.}.cc{debug/}.obj::

$(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug/ @<<

$<

<<

 

{.}.cxx{debug/}.obj::

$(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug/ @<<

$<

<<

 

{.}.c{debug/}.obj::

$(CC) -c $(CFLAGS) $(INCPATH) -Fodebug/ @<<

$<

<<

 

####### Build rules

first: all

all: Makefile.Debug $(DESTDIR_TARGET)

 

$(DESTDIR_TARGET):  $(OBJECTS) 

$(LINK) $(LFLAGS) /OUT:$(DESTDIR_TARGET) @<< 

 $(OBJECTS) $(LIBS)

<<

mt.exe -nologo -manifest "debug/temp.intermediate.manifest" -outputresource:$(DESTDIR_TARGET);1

 

qmake:  FORCE

@$(QMAKE) -win32 -o Makefile.Debug temp.pro

 

dist:

$(ZIP) temp.zip $(SOURCES) $(DIST) temp.pro d:/Qt/4.5.3/mkspecs/qconfig.pri d:/Qt/4.5.3/mkspecs/features/qt_functions.prf d:/Qt/4.5.3/mkspecs/features/qt_config.prf d:/Qt/4.5.3/mkspecs/features/exclusive_builds.prf d:/Qt/4.5.3/mkspecs/features/default_pre.prf d:/Qt/4.5.3/mkspecs/features/win32/default_pre.prf d:/Qt/4.5.3/mkspecs/features/debug.prf d:/Qt/4.5.3/mkspecs/features/debug_and_release.prf d:/Qt/4.5.3/mkspecs/features/default_post.prf d:/Qt/4.5.3/mkspecs/features/win32/default_post.prf d:/Qt/4.5.3/mkspecs/features/build_pass.prf d:/Qt/4.5.3/mkspecs/features/win32/rtti.prf d:/Qt/4.5.3/mkspecs/features/win32/exceptions.prf d:/Qt/4.5.3/mkspecs/features/shared.prf d:/Qt/4.5.3/mkspecs/features/win32/embed_manifest_exe.prf d:/Qt/4.5.3/mkspecs/features/win32/embed_manifest_dll.prf d:/Qt/4.5.3/mkspecs/features/warn_on.prf d:/Qt/4.5.3/mkspecs/features/qt.prf d:/Qt/4.5.3/mkspecs/features/win32/thread.prf d:/Qt/4.5.3/mkspecs/features/moc.prf d:/Qt/4.5.3/mkspecs/features/win32/windows.prf d:/Qt/4.5.3/mkspecs/features/win32/stl_off.prf d:/Qt/4.5.3/mkspecs/features/resources.prf d:/Qt/4.5.3/mkspecs/features/uic.prf d:/Qt/4.5.3/mkspecs/features/yacc.prf d:/Qt/4.5.3/mkspecs/features/lex.prf d:/Qt/4.5.3/mkspecs/features/include_source_dir.prf d:/Qt/4.5.3/lib/qtmaind.prl  HEADERS RESOURCES IMAGES SOURCES OBJECTIVE_SOURCES FORMS YACCSOURCES YACCSOURCES LEXSOURCES 

 

clean: compiler_clean 

-$(DEL_FILE) debug/main.obj

-$(DEL_FILE) debug/temp.intermediate.manifest debug/temp.exp debug/temp.pdb debug/temp.ilk vc*.pdb vc*.idb

 

distclean: clean

-$(DEL_FILE) $(DESTDIR_TARGET)

-$(DEL_FILE) Makefile.Debug

 

mocclean: compiler_moc_header_clean compiler_moc_source_clean

 

mocables: compiler_moc_header_make_all compiler_moc_source_make_all

 

compiler_moc_header_make_all:

compiler_moc_header_clean:

compiler_rcc_make_all:

compiler_rcc_clean:

compiler_image_collection_make_all: qmake_image_collection.cpp

compiler_image_collection_clean:

-$(DEL_FILE) qmake_image_collection.cpp

compiler_moc_source_make_all:

compiler_moc_source_clean:

compiler_uic_make_all:

compiler_uic_clean:

compiler_yacc_decl_make_all:

compiler_yacc_decl_clean:

compiler_yacc_impl_make_all:

compiler_yacc_impl_clean:

compiler_lex_make_all:

compiler_lex_clean:

compiler_clean: 

 

####### Compile

debug/main.obj: main.cpp 

 

####### Install

install:   FORCE

 

uninstall:   FORCE

 

FORCE:

}

抱歉!评论已关闭.