gpt4 book ai didi

c - waf - 构建有效,自定义构建目标失败

转载 作者:太空宇宙 更新时间:2023-11-04 03:02:16 26 4
gpt4 key购买 nike

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但这些并没有为我提供有值(value)的信息来解决这个问题。

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

最佳答案

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

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文件后不要忘记重新配置。

关于c - waf - 构建有效,自定义构建目标失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10064186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com