How to specify gcc flags (CXXFLAGS), especially for a specific module?

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

I tried: CXXFLAGS="-std=c++0x" waf configure , and then built it. However, it turns out that some of the exsiting modules, such as the ipv4 address, are not compatible with c++11 . Thus, I want to specify this flag, especially for my new module, so that other modules do not run in C ++ 11.

I tried adding this in wscript to my new module:

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

It does not work as a first test.

How can i do this?

+8
source share
2 answers

According to waf-book 1.7.8, sections 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 No. 1 - This code consists of two examples presented in a wafbook and not tested at all.

Note # 2 - you may need to make waf aware of the "myobjects" generated, or they cannot be used to build "myshlib" since waf indexes all files before they are created.

+1
source

Although @drahnr's answer is correct for a vanilla waf, it will not work with the NS-3 build system, which the OP seems to need. To add CXXFLAGS to an NS-3 program, you can add them to the assembly object, rather than at 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'] 
+1
source

All Articles