ns3 ./waf快速上手

项目的大致目录结构

$ tree
|-- src
|   `-- wscript
`-- wscript

主目录下有一个主的wscript脚本,要编译的子目录src目录下也有一个wscript脚本(每个wscript是python脚本)

  • 主目录的wscript内容
#! /usr/bin/env python
# encoding: utf-8
	// 这里的注释应该是井号的 
	// 说明: 设置top目录为当前路径,输出路径为当前目录的build目录
top = '.'			
out = 'build'
 
def configure(ctx):
	print(' -> configureing the project in ' + ctx.path.abspath())
 
def ping(ctx):
	print('-> ping from ' + ctx.path.abspath())
	ctx.recurse('src')

小tip:最前面这行是使用python编译这个脚本的意思。就象有些bash脚本里面是#!bash 表示这是命令行的脚本文件一样。

  • src目录下的wscript内容
#! /usr/bin/env python
#encoding: utf-8
def ping(ctx):
	print('-> ping from ' + ctx.path.abspath())



./waf 函数讲解

(1) 首先执行

$  waf configure
Setting top to                           : /home/fcx/share/test/waf_learn/simple_test
Setting out to                           : /home/fcx/share/test/waf_learn/simple_test/build
 -> configureing the project in /home/fcx/share/test/waf_learn/simple_test
'configure' finished successfully (0.036s)

于是在新建的build目录会生成一下配置文件

|-- build
|   |-- c4che
|   |   |-- build.config.py
|   |   `-- _cache.py
|   `-- config.log
|--.lock-wafbuild
|-- src
|   `-- wscript
`-- wscript

其中配置数据存储在build/c4che/目录下,命令行选项和环境变量存储在build.config.py中。用户的配置设置存储在_cache.py中。

(2)然后执行:

$  waf ping
-> ping from /home/fcx/share/test/waf_learn/simple_test
-> ping from /home/fcx/share/test/waf_learn/simple_test/src
'ping' finished successfully (0.002s)

(3)waf dist命令
创建一个发布压缩包,包含源代码目录中的所有文件。默认将会把项目代码打包为一个名为noname-1.0.tar.bz2的压缩包,如果要自己命名,则在主wscript脚本的top命令前添加如:

#! /usr/bin/env python
#encoding: utf-8
APPNAME = 'waf_learn'
VERSION = '1.0.0'
top = '.'
out = 'build'
def configure(ctx):
	print(' -> configureing the project in ' + ctx.path.abspath())

def ping(ctx):
	print('-> ping from ' + ctx.path.abspath())
	ctx.recurse('src')

这样生成的压缩包名为:waf_learn-1.0.0.tar.bz2

(4)waf distclean 命令
如果执行 waf distclean 将会删除build的目录。distclean函数不需要在主wscript脚本中定义,如果你自己定义了该函数,则默认的distclean函数调用将会被你定义的函数覆盖。

更多的可以见这个blog https://blog.csdn.net/rical730/article/details/71514404



默认配置

有一个文件记录了默认的配置信息,可以修改它的默认参数,即默认的是激活examples and tests 还是锁死:
文件名叫utils/ .ns3rc文件 $ vim .ns3rc

  • 禁止:

#Set this equal to true if you want examples to be run.
examples_enabled = False
#Set this equal to true if you want tests to be run.
tests_enabled = False

  • 允许:

#Set this equal to true if you want examples to be run.
examples_enabled = True
#Set this equal to true if you want tests to be run.
tests_enabled = True



运行

./waf --run yourprogram //yourprogram.cc
./waf --pyrun yourprogram.py

补充notice

cc文件不要加.cc后缀 不然反而报错


debug

./waf shell
./waf --run yourProgram --command-template=“gdb %s”

e.g.
./waf --run examples/tcp/tcp-star-server --command-template=“gdb %s”

编译好的可执行文件放在…/debug/example/…相应的目录里,自己可以查看到

更多waf相关资源
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值