I'm simulating my application on ns-3, with protocol buffer.
In protoc-generated code, several include are in the following form:
"#include <google/protobuf/stubs/common.h>"
Which gives me compile error:
error: google/protobuf/stubs/common.h: No such file or directory
My question is: how to edit ns-3 build path, say probably in wscript,
so that when ./waf, ns-3 knows the path to google directory, and find
all libraries correctly?
PS 1: protocol buffer package has the hierarchy: protobuf-2.3.0/src/
google/...... I put this package under the same directory with
mercurial-1.5, in which my code is sitted in mercurial-1.5/ns-3.7-
pyviz/scratch
PS 2: adding the path /path_to_google/ into bash .profile seems
doesn't work for me. Although the command "protoc" could find itself,
those header files still couldn't.
Thanks a lot
Zhang Bo
You can try with:
def build(bld):
obj = bld.create_ns3_program('your_program')
obj.source = 'your_program.cc'
obj.env.append_value('CPPPATH', ['/path/to/your_source_files'])
obj.env.append_value('LIBPATH', ['/path/to/your_library'])
obj.env.append_value('LIB', ['your_library'])
Hope it helps.
Thanks a lot for the reply.
I'm still not quite clear. Below is my setup:
scratch/my_program.cc contains main function.
scratch/packets/data_pkt.{h,cc} is my code defining data packet
format, which I want to include in my_program.cc
In this case, should I put a wscript in scratch/packets/ directory
with your suggested def build? Or should I move my code elsewhere
other than scratch?
Thanks
Zhang Bo
c++ -o write_msg addressbook.cc write_msg.cc `pkg-config --cflags --
libs protobuf`
To run my previously mentioned scratch/my_program.cc, what should I do
so that waf knows to set `--cflags --libs protobuf`?
Zhang Bo
Regarding your first question:
> > In this case, should I put a wscript in scratch/packets/ directory
> > with your suggested def build? Or should I move my code elsewhere
> > other than scratch?
I don't think it is a good idea to do this (use of libs etc) in /
scratch.
This is because there is a loop in the main wscript which builds
everything inside /scratch;
so it will use your libraries to every program in scratch.
The approach I would suggest (the one that I use myself) is to create
a directory "your_dir" inside /src, and then:
1. In the wscript in /src, add 'your_dir' at the end of all_modules =
('','',..., 'your_dir')
2. Put everything (my_program.cc, data_pkt.{h,cc}) inside your_dir.
3. Create a wscript inside your_dir with:
a. Code for building data_pkt.{h,cc} (see /src/applications/onoff/
wscript on how to do that)
b. Code for creating your program (the one I provided you
previously)
Regarding your secong question:
> To run my previously mentioned scratch/my_program.cc, what should I do
> so that waf knows to set `--cflags --libs protobuf`?
These are already handled I think, by 'LIBPATH' and 'LIB'.
If you want to add flags you can use 'CCFLAGS' the same way.
Hope it helps.