0

使用添加了 extras/boost.py 的 waf 1.7.9,我发现您必须在配置时获取库,这使得使用不同的库集构建目标变得困难。例如,我有两个程序,一个只需要 boost 中的头文件(程序'a'),另一个使用一些库(程序'b')。这是我的解决方案,但我的问题是:有没有更好/首选的方法来做到这一点?

#! /usr/bin/env python
# encoding: utf-8

def options(opt):
    opt.load('compiler_cxx boost')

def configure(conf):
    conf.load('compiler_cxx boost')

    conf.check_boost()
    conf.env.DEFINES_BOOST = ['NDEBUG']

    conf.env.LIB_BOOST_FILESYSTEM = conf.boost_get_libs('filesystem system')[-1]
    conf.env.LIB_BOOST_PROGRAM_OPTIONS = conf.boost_get_libs('program_options')[-1]

def build(bld):
    # program 'a' requires header-only part of boost
    bld.program(
        target = 'a',
        source = 'a.cpp',
        use = ['BOOST'] )

    # program 'b' requires link to some boost libraries
    bld.program(
        target = 'b',
        source = 'b.cpp',
        use = ['BOOST', 'BOOST_FILESYSTEM', 'BOOST_PROGRAM_OPTIONS'] )
4

1 回答 1

1

我不知道是否有首选方法,但有一种方法我认为它的魔力较小。基本上,不要使用额外的提升。您可以准确指定要包含哪些库而不包含它。

#!/usr/bin/env python
# encoding: utf-8

def options(opt):
    opt.load('compiler_cxx')

def configure(conf):
    conf.load('compiler_cxx')

    # NOTE: The uselib_store keyword argument is not necessary here, it is just added
    # So that it is clear what name is required to use it during building.
    conf.check(compiler='cxx',lib='boost_filesystem',uselib_store='BOOST_FILESYSTEM')
    conf.check(compiler='cxx',lib='boost_program_options',uselib_store='BOOST_PROGRAM_OPTIONS')

    # NOTE: I don't know what DEFINES_BOOST is used for
    # conf.env.DEFINES_BOOST = ['NDEBUG']
    # This will give you a command line define
    conf.define('NDEBUG,'',quote=False)

def build(bld):
    # NOTE: Specifying include directories is dependent on your platform. I think Waf
    # takes care of this for you, but I'm putting it here for effect.
    inc = ['/usr/include']

    # program 'a' requires header-only part of boost
    bld.program(
        target = 'a',
        source = 'a.cpp',
        use = []
        includes = inc )

    # program 'b' requires link to some boost libraries
    bld.program(
        target = 'b',
        source = 'b.cpp',
        use = ['BOOST_FILESYSTEM', 'BOOST_PROGRAM_OPTIONS'],
        includes = inc)
于 2013-03-04T19:11:09.770 回答