I have this Qt program that i am building with waf.I am testing it out in windows and everytime i run the exe file the console opens up. In (Qt)pro file(if build with qmake) you just have to make sure you remove

CONFIG += console

But i am not sure what linker-flag , i have to add in my wscript(waf) to make this happen.I have to specify /SUBSYSTEM: WINDOWS for msvc complier to take my program as windows program

Please help.

my wscript.py

#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2005, 2011 (ita)
"""
Including the moc files *is* the best practice (KDE), not doing it is easy,
but makes the compilations about 30-40% slower on average.
If you still want the slow version (we warned you!), see the example located
in the folder playground/slow_qt/
"""
VERSION='0.0.1'
APPNAME='qt4_test'
top = '.'
out = 'build'
def options(opt): 
    opt.load('compiler_cxx qt4 compiler_c boost')
def configure(conf):
    conf.load('compiler_cxx qt4 compiler_c boost')
    #if conf.env.COMPILER_CXX == 'msvc': g++
    #conf.check_tool('boost')
    conf.env.append_value('CXXFLAGS', ['-DWAF=1']) # test
    #conf.env.append_value('DWAF','1')
    #conf.recurse(subdirs)
    #conf.check_cc( ccflags='-mwindows', mandatory=True, msg='Checking for flags -mwindows')
def build(bld):
    cxxflags = bld.env.commonCxxFlags
    uselibcommon = 'QTCORE QTGUI QTOPENGL QTSVG QWIDGET QTSQL QTUITOOLS QTSCRIPT'
    bld(features = 'qt4 cxx',  includes = '.',source   = 'ListModel.cpp', target = 'ListModel.o', uselib = uselibcommon, cxxflags=cxxflags)
    bld(features = 'qt4 cxx',  includes = '.', source   = 'Model.cpp', target = 'Model.o', uselib = uselibcommon,  cxxflags=cxxflags)
    bld(features = 'qt4 cxx',  includes = '.', source = 'ProxyModel.cpp' , target = 'ProxyModel.o', uselib = uselibcommon, cxxflags=cxxflags)
    flags = cxxflags + ['-DWAF']
    bld(features = 'qt4 cxx',  includes = bld.options.boost_includes, source = 'TableModel.cpp', target = 'TableModel.o', uselib = uselibcommon, cxxflags=flags)
    bld(features = 'qt4 cxx',  includes = '.', source   = 'SongItem.cpp', target = 'SongItem.o',use = 'ListModel.o',  cxxflags=cxxflags)

    use = [ 'sqlite3.o', 'Master.o' , 'DatabaseUtil' , 'SQLiteError.o' ,  'Vector.o' , 'Song.o' , 'Songs.o' , 'SQLiteVector.o' , 'SQLiteVectorIterator.o' , 'ListModel.o' , 'Model.o' , 'TableModel.o' , 'SongItem.o'  ,  'ProxyModel.o']
    bld(features = 'qt4 cxx c', uselib = uselibcommon, includes = bld.options.boost_includes , source   = 'MainWindow.cpp' , target = 'MainWindow.o', lib = ['phonon'], libpath = ['/usr/lib'], use = use, cxxflags=cxxflags)

    use = [ 'sqlite3.o', 'Master.o' , 'DatabaseUtil' , 'SQLiteError.o' ,  'Vector.o' , 'Song.o' , 'Songs.o' , 'SQLiteVector.o' , 'SQLiteVectorIterator.o' , 'ListModel.o' , 'Model.o' , 'TableModel.o' , 'SongItem.o'  , 'ProxyModel.o',
    'MainWindow.o']
    bld(features = 'qt4 cxx cxxprogram', includes = bld.options.boost_includes, source = 'main.cpp MasterDetail.qrc', target   = 'app', uselib = uselibcommon , cxxflags=cxxflags, use = use, linkflags = (['-Wl,-subsystem,windows']) )

from waflib.TaskGen import feature, before_method, after_method
@feature('cxx')
@after_method('.')
@before_method('apply_incpaths')
def add_includes_paths(self):
        incs = set(self.to_list(getattr(self, 'includes', '')))
        for x in self.compiled_tasks:
                incs.add(x.inputs[0].parent.path_from(self.path))
        self.includes = list(incs)
有帮助吗?

解决方案

I got the solution

on windows, use(mingw)

linkflags = ['-Wl,-subsystem,windows'], -> to disable the console
linkflags = ['-Wl,-subsystem,console'], -> to enable the console

use (msvc)

subsystem='windows', -> to disable the console
subsystem='console', -> to enable the console

其他提示

I think you need /SUBSYSTEM:WINDOWS, rather than /SUBSYSTEM = WINDOWS.

Once I used a hackish method - when an app, depending on command line flags had to behave either as a console app or as a UI app (without console). It boiled down (under Windows) to building it as a console application and getting rid of console if certain conditions were met:

#include <windows.h>

if(getRidOfTheConsole)
    FreeConsole();

The alternative option (already known to you) is to use /SUBSYSTEM:WINDOWS. I don't know how to put it in waf, however there is one more way - put the following in your file with int main():

#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top