I want to add external library on ns3, for example ffmpeg.The fllowing is what I do to make it work.
In the cteated module that need to be linked to the external library, the wscript should be similar to the following.
wscript
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
# def options(opt):
# pass
# def configure(conf):
# conf.check_nonfatal(header_name='stdint.h', define_name='HAVE_STDINT_H')
def configure(conf):
#libs_check = ['/home/zsy/ffmpeg-0.8.5/libavformat/','/home/zsy/ffmpeg-0.8.5/libavcodec/','/home/zsy/ffmpeg-0.8.5/libavutil/']
#conf.env.LIBPATH_LIBNAME = libs_check
conf.env.append_value("CXXFLAGS", ["-ggdb", "-g3", "-O0", "-D__STDC_CONSTANT_MACROS"])
conf.env.append_value('INCLUDES', ['/home/zsy/ffmpeg-0.8.5/'])
conf.env.append_value("CFLAGS", ["-ggdb", "-g3", "-O0", "-D__STDC_CONSTANT_MACROS"])
conf.env.append_value("LINKFLAGS", ["-ldl","-lavcodec", "-lavformat", "-lavutil"])
conf.env.append_value("LINKFLAGS", ['-L/home/zsy/ffmpeg-0.8.5/libavformat/','-L/home/zsy/ffmpeg-0.8.5/libavcodec/','-L/home/zsy/ffmpeg-0.8.5/libavutil/'])
#conf.env['libavformat']= conf.check(mandatory=True,libpath=['/home/zsy/ffmpeg-0.8.5/libavformat/'],includes=['/home/zsy/ffmpeg-0.8.5/'],lib='avformat', uselib_store='libavformat')
conf.env['libavformat']= conf.check(mandatory=True,lib='avformat', uselib_store='libavformat')
conf.env['libavcodec']= conf.check(mandatory=True,lib='avcodec', uselib_store='libavcodec')
conf.env['libavutil']= conf.check(mandatory=True, lib='avutil', uselib_store='libavutil')
conf.check_cxx(lib='avutil')
conf.check_cxx(lib='avcodec')
conf.check_cxx(lib='avformat')
#conf.pkg_check_modules('avformat', 'libavformat', mandatory=True)
conf.env['ldl']= conf.check(mandatory=True, lib='dl', uselib_store='LDL')
But its not enough, the above just make the module can be compile as library sucessfully. If you create an executable code with a main function under the file Scratch in ns2, you should add the external dynamic library path to the environment variable.
sudo gedit /etc/profile and add the following to the profile
export LD_LIBRARY_PATH=/home/zsy/ffmpeg-0.8.5/libavformat/:/home/zsy/ffmpeg-0.8.5/libavcodec/:/home/zsy/ffmpeg-0.8.5/libavutil/:$LD_LIBRARY_PATH
I compile ffmpeg under the path “/home/zsy/ffmpeg-0.8.5/”.