How to specify gcc flags (CXXFLAGS) particularly for a specific module?
Asked Answered
D

2

9

I am building a new NS3 module recently. In my code, I use something new features of the C++11 (c++0x), I want to add a gcc flags (CXXFLAGS) "-std=c++0x" to the waf configuration system.

I tried to this: CXXFLAGS="-std=c++0x" waf configure, and then build it. However, it turns out that some of the exsiting modules such as ipv4-address is not compatible to c++11. Thus, I want to specify this flag particularly for my new module so that other modules won't be complied on c++11.

I tried to add this to the wscript in my new module:

def configure(conf):
    conf.env.append_value('CXXFLAGS', '-std=c++0x')

It fails as the first trial.

How can I do that?

Dagny answered 4/12, 2012 at 10:40 Comment(1)
Doesn't adding -std=c++0x in configure sets it globally?Spontaneous
I
4

Although @drahnr's answer is correct for vanilla waf, it won't work with NS-3's build system, which is apparently what OP wants. To add CXXFLAGS to an NS-3 program, you can add them to the build object instead of in the configuration stage.

For example:

def build(bld):   
    obj = bld.create_ns3_program('my_app', ['core', 'other-dependencies'])
    obj.source = 'MyApplication.cpp'
    obj.cxxflags = ['-std=c++11']
Ivonneivor answered 22/12, 2013 at 20:44 Comment(0)
C
2

According to the waf book 1.7.8, section 10.1.1 and 10.1.2

    bld.shlib(source='main.c',
            target='myshlib',
            cflags       = ['-O2', '-Wall'], 
            cxxflags     = ['-O3', '-std=c++0x'],
            use          = 'myobjects')

    bld.objects(source='ip4.c',
            cflags       = ['-O2', '-Wall'], 
            cxxflags     = ['-std=somethingelse'],
            target       = 'myobjects')

Note #1 - this code is composed of the 2 examples provided in the wafbook and not tested at all.

Note #2 - you may need to make waf aware of 'myobjects' generated or they may not be used to build 'myshlib', as waf indexes all files before building.

Casandracasanova answered 18/12, 2012 at 8:5 Comment(1)
but the NS3 waf system is so complicated that they organize the source and targets not in this manner...Dagny

© 2022 - 2024 — McMap. All rights reserved.