【问题标题】:waf - build works, custom build targets failwaf - 构建工作,自定义构建目标失败
【发布时间】:2012-04-21 07:02:36
【问题描述】:

waf 命令waf build 显示编译器错误(如果有的话),而waf debugwaf release 不显示并且总是 失败,使用以下 wscript 文件(或者可能是 wscript 文件还有一些我目前不知道的缺点):

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,但这些演示并没有为我提供有价值的信息来解决此问题。

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

【问题讨论】:

    标签: c build waf


    【解决方案1】:

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

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

    由于cfg.setenv 函数重置了整个以前的环境。如果你想保存以前的环境,你可以做cfg.setenv('debug', env=cfg.env.derive())

    另外,您不需要显式指定features = ['c', 'cprogram'],因为当您调用bld.program(...) 时,它是多余的。

    附:修改wscript文件后不要忘记重新配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-17
      • 1970-01-01
      • 2016-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多