1

waf 命令使用以下 wscript 文件(或者 wscript 文件有一些我目前不知道的其他缺点waf build)显示编译器错误(如果有的话),waf debug无论waf release是否总是失败:

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 演示,阅读了第 6.2.2 节中的 wafbook,但这些并没有为我提供有价值的信息来解决这个问题。

出了什么问题,我该如何解决?

4

1 回答 1

2

您至少需要执行以下操作:

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

由于该cfg.setenv功能会重置整个以前的环境。如果要保存以前的环境,可以执行cfg.setenv('debug', env=cfg.env.derive()).

Also, you don't need to explicitly specify the features = ['c', 'cprogram'], since, it's redundant, when you call bld.program(...).

P.S. Don't forget to reconfigure after modifying wscript file.

于 2012-04-08T17:05:44.883 回答