blob: 22b71ac1bcbcc8cdf955cce5170a8e487d2de1b8 [file] [log] [blame] [view]
Alexander Afanasyev28d0d942015-01-04 14:52:19 -08001ndn-cxx examples
2================
3
4By default, examples in `examples/` folder are not built. To enable them, use
5`--with-examples` configure option. For example:
6
7 ./waf configure --with-examples
8 ./waf
9
10There are two ways to add new examples, depending on their complexity:
11
121. Examples with a single translation unit
13
14 For simple examples that have a single translation unit, the `.cpp` file can be directly put
15 in `examples/` folder and it will be automatically compiled on the next run of `./waf`. Name
16 of the compiled binary will be determined by the base name of the `.cpp` file. For example,
17 `examples/foo.cpp` will be compiled into binary `foo` in `<build>/examples` folder:
18
19 echo "int main() { return 0; }" > examples/foo.cpp
20 ./waf
21 # ... Compiling examples/foo.cpp
22 # ... Linking build/examples/foo
23
24 # To run the example
25 ./build/examples/foo
26
272. Examples with multiple translation units
28
29 For more complex examples that contain multiple translation units, one can use
30 the following directory structure:
31
32 - Create a directory under `examples/` folder (e.g., `examples/bar`).
33 The name of this directory will determine the name of the compiled binary
34 (`<build>/examples/bar/bar`)
35
36 - Place any number of translation units (e.g., `examples/bar/a.cpp`, `examples/bar/b.cpp`,
37 ...) in this directory. All `.cpp` files in this directory will be compiled and linked
38 together to produce the binary of the example. One of the .cpp files should contain
39 the `main()` function.
40
41 For example:
42
43 mkdir examples/bar
44 echo "int bar(); int main() { return bar(); }" > examples/bar/a.cpp
45 echo "int bar() { return 10; } " > examples/bar/b.cpp
46 ./waf
47 # ... Compiling examples/bar/a.cpp
48 # ... Compiling examples/bar/b.cpp
49 # ... Linking build/examples/bar/bar
50
51 # To run the example
52 ./build/examples/bar/bar