blob: d3cef229774b18be74d812a9adf80a7ca3e0b034 [file] [log] [blame]
Alexander Afanasyevabaab522014-04-30 20:42:11 -07001.. _Getting Started with ndn-cxx:
2
Alexander Afanasyevc5452c52014-04-29 17:21:51 -07003Getting started with ndn-cxx
4============================
5
6Supported platforms
7-------------------
8
9ndn-cxx uses continuous integration and has been tested on the following
10platforms:
11
Ivan Yeoba1a4a92015-01-11 00:45:57 -080012- Ubuntu 14.04 (64-bit and 32-bit)
Davide Pesaventoe11c8d82016-04-16 14:32:07 +020013- Ubuntu 16.04 (64-bit and 32-bit)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070014- OS X 10.8
15- OS X 10.9
Ivan Yeoba1a4a92015-01-11 00:45:57 -080016- OS X 10.10
Davide Pesaventoe11c8d82016-04-16 14:32:07 +020017- OS X 10.11
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070018
19ndn-cxx is known to work on the following platforms, although they are not officially
20supported:
21
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070022- Fedora >= 20
Ivan Yeoba1a4a92015-01-11 00:45:57 -080023- CentOS >= 6.2
24- Gentoo Linux
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070025- FreeBSD >= 10.0
Ivan Yeoba1a4a92015-01-11 00:45:57 -080026- Raspbian >= 3.12
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070027
28Prerequisites
29-------------
30
31Required:
32~~~~~~~~~
33
34- ``python`` >= 2.6
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070035- ``libsqlite3``
36- ``libcrypto++``
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070037- OpenSSL version >= 1.0
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070038- ``pkg-config``
Davide Pesaventoe6e6fde2016-04-16 14:44:45 +020039- Boost libraries >= 1.54
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070040- OSX Security framework (on OSX platform only)
41
42Following are the detailed steps for each platform to install the compiler, all necessary
43development tools and libraries, and ndn-cxx prerequisites.
44
45- OS X
46
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070047 Install Xcode from AppStore or at least Command Line Tools (``xcode-select --install``)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070048
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070049 * When using MacPorts
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070050
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070051 In a terminal, enter::
52
53 sudo port install pkgconfig boost sqlite3 libcryptopp openssl
54
55 * When using Homebrew
56
57 In a terminal, enter::
58
59 brew install boost pkg-config cryptopp openssl
60 brew link --force openssl
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070061
Junxiao Shi190bee22015-02-14 19:21:36 -070062 .. note::
63
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070064 If a major OS X system upgrade is performed after installing dependencies with
65 MacPorts or Homebrew, remember to reinstall all packages.
Junxiao Shi190bee22015-02-14 19:21:36 -070066
Ivan Yeoba1a4a92015-01-11 00:45:57 -080067- Ubuntu
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070068
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070069 In a terminal, enter::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070070
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070071 sudo apt-get install build-essential libcrypto++-dev libsqlite3-dev libboost-all-dev libssl-dev
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070072
Ivan Yeoba1a4a92015-01-11 00:45:57 -080073- Fedora
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070074
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070075 In a terminal, enter::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070076
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070077 sudo yum install gcc-g++ git
78 sudo yum install sqlite-devel cryptopp-devel boost-devel openssl-devel
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070079
80Optional:
81~~~~~~~~~
82
83To build tutorials, manpages, and API documentation the following
84dependencies need to be installed:
85
86- ``doxygen``
87- ``graphviz``
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -070088- ``python-sphinx`` and sphinx extensions ``sphinxcontrib-doxylink``,
89 ``sphinxcontrib-googleanalytics``
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070090
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -070091The following lists steps for common platforms to install these prerequisites:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070092
Ivan Yeoba1a4a92015-01-11 00:45:57 -080093- On OS X with MacPorts::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070094
95 sudo port install doxygen graphviz py27-sphinx sphinx_select
96 sudo port select sphinx py27-sphinx
97
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -070098 # Install sphinx extensions
99 sudo port install py27-pip
100 sudo port select pip pip27
101 sudo pip install sphinxcontrib-doxylink sphinxcontrib-googleanalytics
102
Ivan Yeoba1a4a92015-01-11 00:45:57 -0800103- On Ubuntu::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700104
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700105 sudo apt-get install doxygen graphviz python-sphinx python-pip
106 sudo pip install sphinxcontrib-doxylink sphinxcontrib-googleanalytics
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700107
Ivan Yeoba1a4a92015-01-11 00:45:57 -0800108- On Fedora::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700109
Alexander Afanasyev5946ed12015-01-19 23:41:39 -0800110 sudo yum install doxygen graphviz python-sphinx
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700111 sudo pip install sphinxcontrib-doxylink sphinxcontrib-googleanalytics
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700112
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700113.. _build:
114
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700115Build
116-----
117
118(These are instructions to build ndn-cxx. To do development of ndn-cxx
119code and update the build system, see Development.)
120
121To build in a terminal, change directory to the ndn-cxx root. Enter:
122
123::
124
125 ./waf configure
126 ./waf
127 sudo ./waf install
128
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700129By default, only the shared version of ndn-cxx library is built. To build the static library,
130use ``--enable-static`` option for ``./waf configure`` command. For example::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700131
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700132 ./waf configure --enable-static
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700133
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700134To disable build of the shared library and build only the static library, use additional
135``--disable-shared`` option. Note that at least one version of the library needs to be
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700136enabled.
137
138::
139
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700140 ./waf configure --enable-static --disable-shared
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700141
142
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700143After the shared library is built and installed, some systems require additional actions.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700144
145 - on Linux::
146
147 sudo ldconfig
148
149 - on FreeBSD::
150
151 sudo ldconfig -m
152
153 .. note::
154 When library is installed in a non-standard path (in general: not in ``/usr/lib`` or
155 ``/usr/local/lib``; on some Linux distros including Fedora: not in ``/usr/lib``),
156 additional actions may be necessary.
157
158 The installation path should be added to ``/etc/ld.so.conf`` (or in
159 ``/etc/ld.so.conf.d``) **before** running ``sudo ldconfig``. For example::
160
161 echo /usr/local/lib | sudo tee /etc/ld.so.conf.d/ndn-cxx.conf
162
163 Alternatively, ``LD_LIBRARY_PATH`` environment variable should be set to the location of
164 the library::
165
166 export LD_LIBRARY_PATH=/usr/local/lib
167
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700168This builds and installs the following items:
169
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700170- ``<LIBPATH>/libndn-cxx.a``: static NDN C++ library (if enabled)
171- ``<LIBPATH>/libndn-cxx.so``, ``<LIBPATH>/libndn-cxx.so.<VERSION>`` (on Linux),
172 ``<LIBPATH>/libndn-cxx.dylib``, ``<LIBPATH>/libndn-cxx.<VERSION>.dylib`` (on OS X):
173 shared NDN C++ library (if enabled)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700174- ``<LIBPATH>/pkgconfig/libndn-cxx.pc``: pkgconfig file storing all
175 neccessary flags to build against the library. For example, if
176 pkgconfig or pkgconf package is installed and ``PKG_CONFIG_PATH`` is
177 configured properly (or ``<LIBPATH>/pkgconfig`` is a default path),
178 ``pkgconfig --libs --clflags libndn-cxx`` will return all necessary
179 compile and link flags for the library.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700180- ``<BINPATH>/ndnsec``: tool to manage NDN keys and certificates
181- ``<BINPATH>/ndnsec-*``: convenience scripts for ``ndnsec`` tools
182
183If configured with tests: ``./waf configure --with-tests``), the above
184commands will also produce:
185
186- ``build/unit-tests``: A unit test binary for the library
187
Junxiao Shie04bd832014-11-29 23:02:38 -07001881.5GB available memory per CPU core is necessary for efficient compilation.
189On a multi-core machine with less than 1.5GB available memory per CPU core,
190limit the objects being compiled in parallel with ``./waf -jN`` where N is the amount
191of available memory divided by 1.5GB (eg. ``./waf -j1`` for 1.5GB memory),
192which could usually avoid memory thrashing and result in faster compilation.
193
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700194Build with examples
195-------------------
196
197By default, examples in ``examples/`` are not build. To enable them, use
198``--with-examples`` configure option:
199
200::
201
202 ./waf configure --with-examples
203 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700204 sudo ./waf install
205
206:ref:`Additional step <build>`:
207
208 - on Linux::
209
210 sudo ldconfig
211
212 - on FreeBSD::
213
214 sudo ldconfig -m
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700215
216To run examples:
217
218::
219
220 # trivial producer app
221 ./build/examples/producer
222
223 # trivial consumer app
224 ./build/examples/consumer
225
226 # trivial consumer app with timers
227 ./build/examples/consumer-with-timer
228
229If you want to test out a sample application, just create a ``.cpp`` file in ``examples/``
230folder and it will be compiled on the next run on ``./waf``. For example:
231
232::
233
234 cp examples/consumer.cpp examples/my-new-consumer-app.cpp
235 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700236 sudo ./waf install
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700237 ./build/examples/my-new-consumer-app
238
239
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700240Debug symbols
241~~~~~~~~~~~~~
242
243The default compiler flags enable debug symbols to be included in binaries (i.e., ``-g``
244flag for ``./waf configure`` and ``-g3`` for ``./waf configure --debug``). This
245potentially allows more meaningful debugging information if your application crashes.
246
247If it is undesirable, default flags can be easily overridden:
248
249::
250
251 CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc
252 ./waf
253 sudo ./waf install
254
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700255:ref:`Additional step <build>`:
256
257 - on Linux::
258
259 sudo ldconfig
260
261 - on FreeBSD::
262
263 sudo ldconfig -m
264
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700265Documentation
266-------------
267
268ndn-cxx tutorials and API documentation can be built using the following
269commands:
270
271::
272
273 # Full set of documentation (tutorials + API) in build/docs
274 ./waf docs
275
276 # Only tutorials in `build/docs`
277 ./waf sphinx
278
279 # Only API docs in `build/docs/doxygen`
280 ./waf doxgyen
281
282Manpages are automatically created and installed during the normal build
283process (e.g., during ``./waf`` and ``./waf install``), if
284``python-sphinx`` module is detected during ``./waf configure`` stage.
285By default, manpages are installed into ``${PREFIX}/share/man`` (where
286default value for ``PREFIX`` is ``/usr/local``). This location can be
287changed during ``./waf configure`` stage using ``--prefix``,
288``--datarootdir``, or ``--mandir`` options.
289
290For more details, refer to ``./waf --help``.
291
292Development Build
293-----------------
294
295The following is the suggested configure commands for development build.
296
297::
298
299 ./waf configure --debug --with-tests
300 ./waf
301 sudo ./waf install
302
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700303:ref:`Additional step <build>`:
304
305 - on Linux::
306
307 sudo ldconfig
308
309 - on FreeBSD::
310
311 sudo ldconfig -m
312
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700313In the development build all compiler optimizations are disabled by
314default and all warnings are treated as error. The default behavior can
315be overridden by setting ``CXXFLAGS`` environment variable before
316running ``./waf configure``:
317
318::
319
320 CXXFLAGS="-O1 -g3" ./waf configure --debug --with-tests
321 ...
Alexander Afanasyev5946ed12015-01-19 23:41:39 -0800322
323Customize Compiler
324------------------
325
326To customize compiler, set ``CXX`` environment variable to point to compiler binary and, in
327some case, specify type of the compiler using ``--check-cxx-compiler``. For example, when
328using clang compiler on Linux system, use the following:
329
330::
331
332 CXX=clang++ ./waf configure --check-cxx-compiler=clang++