2012-04-08 73 views
1

WAF的命令waf build顯示編譯器錯誤(如果有的話),而waf debugwaf release不和總是失敗,利用下列WScript的文件(或者也許是WScript的文件有一些等缺點我目前不知道的):WAF - 建設工程,自定義生成目標失敗

APPNAME = 'waftest' 
VERSION = '0.0.1' 
def configure(ctx): 
    ctx.load('compiler_c') 
    ctx.define('VERSION', VERSION) 
    ctx.define('GETTEXT_PACKAGE', APPNAME) 

    ctx.check_cfg(atleast_pkgconfig_version='0.1.1') 
    ctx.check_cfg(package='glib-2.0', uselib_store='GLIB', args=['--cflags', '--libs'], mandatory=True) 
    ctx.check_cfg(package='gobject-2.0', uselib_store='GOBJECT', args=['--cflags', '--libs'], mandatory=True) 
    ctx.check_cfg(package='gtk+-3.0', uselib_store='GTK3', args=['--cflags', '--libs'], mandatory=True) 
    ctx.check_cfg(package='libxml-2.0', uselib_store='XML', args=['--cflags', '--libs'], mandatory=True) 

    ctx.check_large_file(mandatory=False) 
    ctx.check_endianness(mandatory=False) 
    ctx.check_inline(mandatory=False) 

    ctx.setenv('debug') 
    ctx.env.CFLAGS = ['-g', '-Wall'] 
    ctx.define('DEBUG',1) 

    ctx.setenv('release') 
    ctx.env.CFLAGS = ['-O2', '-Wall'] 
    ctx.define('RELEASE',1) 




def pre(ctx): 
    print ('Building [[[' + ctx.variant + ']]] ...') 


def post(ctx): 
    print ('Building is complete.') 

def build(ctx): 
    ctx.add_pre_fun(pre) 
    ctx.add_post_fun(post) 

# if not ctx.variant: 
#  ctx.fatal('Do "waf debug" or "waf release"') 

    exe = ctx.program(
     features = ['c', 'cprogram'], 
     target = APPNAME+'.bin', 
     source = ctx.path.ant_glob(['src/*.c']), 
     includes = ['src/'], 
     export_includes = ['src/'], 
     uselib = 'GOBJECT GLIB GTK3 XML' 
    ) 
# for item in exe.includes: 
#  print(item) 



from waflib.Build import BuildContext 

class release(BuildContext): 
    cmd = 'release' 
    variant = 'release' 

class debug(BuildContext): 
    cmd = 'debug' 
    variant = 'debug' 

錯誤從waf debug導致:

Build failed 
-> task in 'waftest.bin' failed (exit status -1): 
    {task 46697488: c qqq.c -> qqq.c.1.o} 
[useless filepaths] 

我看看WAF的演示,閱讀wafbook at section 6.2.2但那些沒有爲我提供有價值的信息來解決這個問題。

怎麼回事,我該如何解決?

回答

2

你至少需要做到以下幾點:

def configure(ctx): 
    ... 
    ctx.setenv('debug') 
    ctx.load('compiler_c') 
    ... 

由於cfg.setenv功能將整個以前的環境。如果你想保存以前的環境,你可以做cfg.setenv('debug', env=cfg.env.derive())

此外,您不需要明確指定features = ['c', 'cprogram'],因爲當您撥打bld.program(...)時,這是多餘的。

P.S.不要忘記在修改wscript文件後重新配置。