blob: b2ab18dd638b2764727cc6ab4d007038b2633271 [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
Davide Pesavento7c4ad512018-04-28 15:20:11 -040012- Ubuntu 16.04 (amd64, armhf, i386)
13- Ubuntu 18.04 (amd64)
Alexander Afanasyev0d748af2019-04-25 17:45:07 -040014- Ubuntu 19.04 (amd64)
Davide Pesavento0530b5b2016-11-07 03:23:58 +010015- macOS 10.12
Eric Newberry935d7fe2017-10-29 15:09:36 -070016- macOS 10.13
Davide Pesavento534b8412018-12-08 19:19:09 -050017- macOS 10.14
Alexander Afanasyev0d748af2019-04-25 17:45:07 -040018- CentOS 7 (with gcc 7 and boost 1.58.0)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070019
20ndn-cxx is known to work on the following platforms, although they are not officially
21supported:
22
Davide Pesavento7c4ad512018-04-28 15:20:11 -040023- Debian >= 9
24- Fedora >= 24
Ivan Yeoba1a4a92015-01-11 00:45:57 -080025- Gentoo Linux
Davide Pesavento7c4ad512018-04-28 15:20:11 -040026- Raspbian >= 2017-08-16
Davide Pesavento534b8412018-12-08 19:19:09 -050027- FreeBSD 11.2
28
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070029
30Prerequisites
31-------------
32
33Required:
34~~~~~~~~~
35
Davide Pesaventoca660f12018-06-16 14:01:51 -040036- GCC >= 5.3, or clang >= 3.6
Davide Pesavento7c4ad512018-04-28 15:20:11 -040037- ``python2`` >= 2.7, or ``python3`` >= 3.4
Davide Pesavento844b0932018-05-07 01:00:16 -040038- Boost libraries >= 1.58
Davide Pesavento534b8412018-12-08 19:19:09 -050039- ``pkg-config``
40- SQLite 3.x
41- OpenSSL >= 1.0.2
42- Apple Security framework (on macOS only)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070043
44Following are the detailed steps for each platform to install the compiler, all necessary
45development tools and libraries, and ndn-cxx prerequisites.
46
Davide Pesavento534b8412018-12-08 19:19:09 -050047- macOS
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070048
Davide Pesavento534b8412018-12-08 19:19:09 -050049 * Install Xcode from the App Store, or at least the Command Line Tools
50 (``xcode-select --install``)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070051
Davide Pesavento534b8412018-12-08 19:19:09 -050052 * If using Homebrew (recommended), enter the following in a terminal::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070053
Davide Pesavento534b8412018-12-08 19:19:09 -050054 brew install boost openssl pkg-config
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070055
Davide Pesavento534b8412018-12-08 19:19:09 -050056 .. note::
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070057
Davide Pesavento534b8412018-12-08 19:19:09 -050058 If a major OS upgrade is performed after installing the dependencies
59 with Homebrew, remember to reinstall all packages.
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070060
Davide Pesavento534b8412018-12-08 19:19:09 -050061- Ubuntu
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070062
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070063 In a terminal, enter::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070064
Alexander Afanasyev0d748af2019-04-25 17:45:07 -040065 sudo apt install build-essential libboost-all-dev libssl-dev libsqlite3-dev pkg-config python-minimal
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070066
Ivan Yeoba1a4a92015-01-11 00:45:57 -080067- Fedora
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
Davide Pesavento534b8412018-12-08 19:19:09 -050071 sudo yum install gcc-g++ sqlite-devel boost-devel openssl-devel
72
73- FreeBSD
74
75 In a terminal, enter::
76
77 sudo pkg install python pkgconf sqlite3 boost-libs
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070078
79Optional:
80~~~~~~~~~
81
82To build tutorials, manpages, and API documentation the following
83dependencies need to be installed:
84
85- ``doxygen``
86- ``graphviz``
Davide Pesavento534b8412018-12-08 19:19:09 -050087- ``python-sphinx``
88- ``sphinxcontrib-doxylink``
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070089
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -070090The following lists steps for common platforms to install these prerequisites:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070091
Davide Pesavento534b8412018-12-08 19:19:09 -050092- On macOS with Homebrew and pip::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070093
Davide Pesavento534b8412018-12-08 19:19:09 -050094 brew install doxygen graphviz
95 sudo pip install sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070096
Davide Pesavento534b8412018-12-08 19:19:09 -050097- On Ubuntu::
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -070098
Davide Pesavento534b8412018-12-08 19:19:09 -050099 sudo apt install doxygen graphviz python3-pip
100 sudo pip3 install sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700101
Davide Pesavento534b8412018-12-08 19:19:09 -0500102- On Fedora::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700103
Davide Pesavento534b8412018-12-08 19:19:09 -0500104 sudo yum install doxygen graphviz python-sphinx
105 sudo pip install sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700106
Davide Pesavento534b8412018-12-08 19:19:09 -0500107- On FreeBSD::
108
109 sudo pkg install doxygen graphviz py27-sphinx
110
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700111
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700112.. _build:
113
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700114Build
115-----
116
Davide Pesavento534b8412018-12-08 19:19:09 -0500117.. note::
118 These are instructions for regular builds of ndn-cxx (release mode).
119 To do development of ndn-cxx code itself, see "Development build" below.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700120
Davide Pesavento534b8412018-12-08 19:19:09 -0500121To build in a terminal, change directory to the ndn-cxx root, then enter::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700122
123 ./waf configure
124 ./waf
125 sudo ./waf install
126
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700127By default, only the shared version of ndn-cxx library is built. To build the static library,
Davide Pesavento534b8412018-12-08 19:19:09 -0500128use ``--enable-static`` option for ``./waf configure`` command::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700129
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700130 ./waf configure --enable-static
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700131
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700132To disable build of the shared library and build only the static library, use additional
133``--disable-shared`` option. Note that at least one version of the library needs to be
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700134enabled.
135
136::
137
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700138 ./waf configure --enable-static --disable-shared
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700139
Davide Pesavento534b8412018-12-08 19:19:09 -0500140After the shared library is installed, on Linux it is also necessary to run::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700141
Davide Pesavento534b8412018-12-08 19:19:09 -0500142 sudo ldconfig
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700143
Davide Pesavento534b8412018-12-08 19:19:09 -0500144.. note::
145 When the library is installed in a non-standard path (in general: not in ``/usr/lib``
146 or ``/usr/local/lib``; on some Linux distros including Fedora: not in ``/usr/lib``),
147 additional actions may be necessary.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700148
Davide Pesavento534b8412018-12-08 19:19:09 -0500149 The installation path should be added to ``/etc/ld.so.conf`` (or in
150 ``/etc/ld.so.conf.d``) **before** running ``sudo ldconfig``. For example::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700151
Davide Pesavento534b8412018-12-08 19:19:09 -0500152 echo /usr/local/lib | sudo tee /etc/ld.so.conf.d/ndn-cxx.conf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700153
Davide Pesavento534b8412018-12-08 19:19:09 -0500154 Alternatively, the ``LD_LIBRARY_PATH`` environment variable can be set to point to
155 the installation directory of the shared library::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700156
Davide Pesavento534b8412018-12-08 19:19:09 -0500157 export LD_LIBRARY_PATH=/usr/local/lib
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700158
Davide Pesavento534b8412018-12-08 19:19:09 -0500159The ``./waf install`` command installs the following files:
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700160
Davide Pesavento534b8412018-12-08 19:19:09 -0500161- ``<LIBPATH>/libndn-cxx.a``: static NDN C++ library (if enabled).
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700162- ``<LIBPATH>/libndn-cxx.so``, ``<LIBPATH>/libndn-cxx.so.<VERSION>`` (on Linux),
Davide Pesavento534b8412018-12-08 19:19:09 -0500163 ``<LIBPATH>/libndn-cxx.dylib``, ``<LIBPATH>/libndn-cxx.<VERSION>.dylib`` (on macOS):
164 shared NDN C++ library (if enabled).
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700165- ``<LIBPATH>/pkgconfig/libndn-cxx.pc``: pkgconfig file storing all
166 neccessary flags to build against the library. For example, if
Davide Pesavento534b8412018-12-08 19:19:09 -0500167 pkg-config or pkgconf package is installed and ``PKG_CONFIG_PATH`` is
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700168 configured properly (or ``<LIBPATH>/pkgconfig`` is a default path),
169 ``pkgconfig --libs --clflags libndn-cxx`` will return all necessary
170 compile and link flags for the library.
Davide Pesavento534b8412018-12-08 19:19:09 -0500171- ``<BINPATH>/ndnsec``: tool to manage NDN keys and certificates.
172- ``<BINPATH>/ndnsec-*``: convenience aliases for ``ndnsec`` tools.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700173
Davide Pesavento534b8412018-12-08 19:19:09 -0500174If configured with tests (``./waf configure --with-tests``), the above
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700175commands will also produce:
176
Davide Pesavento534b8412018-12-08 19:19:09 -0500177- ``build/unit-tests``: a unit test binary for the library.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700178
Junxiao Shie04bd832014-11-29 23:02:38 -07001791.5GB available memory per CPU core is necessary for efficient compilation.
180On a multi-core machine with less than 1.5GB available memory per CPU core,
181limit the objects being compiled in parallel with ``./waf -jN`` where N is the amount
182of available memory divided by 1.5GB (eg. ``./waf -j1`` for 1.5GB memory),
Davide Pesavento534b8412018-12-08 19:19:09 -0500183which should usually avoid memory thrashing and result in faster compilation.
Junxiao Shie04bd832014-11-29 23:02:38 -0700184
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700185Build with examples
186-------------------
187
Davide Pesavento534b8412018-12-08 19:19:09 -0500188By default, examples in ``examples/`` are not built. To enable them, use the
189``--with-examples`` configure option::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700190
191 ./waf configure --with-examples
192 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700193 sudo ./waf install
Davide Pesavento534b8412018-12-08 19:19:09 -0500194 sudo ldconfig # (on Linux only)
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700195
Davide Pesavento534b8412018-12-08 19:19:09 -0500196To run examples::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700197
198 # trivial producer app
199 ./build/examples/producer
200
201 # trivial consumer app
202 ./build/examples/consumer
203
204 # trivial consumer app with timers
205 ./build/examples/consumer-with-timer
206
207If you want to test out a sample application, just create a ``.cpp`` file in ``examples/``
Davide Pesavento534b8412018-12-08 19:19:09 -0500208folder and it will be compiled on the next run on ``./waf``. For example::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700209
210 cp examples/consumer.cpp examples/my-new-consumer-app.cpp
211 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700212 sudo ./waf install
Davide Pesavento534b8412018-12-08 19:19:09 -0500213 sudo ldconfig # (on Linux only)
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700214 ./build/examples/my-new-consumer-app
215
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700216Debug symbols
217~~~~~~~~~~~~~
218
219The default compiler flags enable debug symbols to be included in binaries (i.e., ``-g``
220flag for ``./waf configure`` and ``-g3`` for ``./waf configure --debug``). This
221potentially allows more meaningful debugging information if your application crashes.
222
Davide Pesavento534b8412018-12-08 19:19:09 -0500223The default build flags can easily be overridden::
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700224
225 CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc
226 ./waf
227 sudo ./waf install
228
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700229
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700230Documentation
231-------------
232
233ndn-cxx tutorials and API documentation can be built using the following
Davide Pesavento534b8412018-12-08 19:19:09 -0500234commands::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700235
236 # Full set of documentation (tutorials + API) in build/docs
237 ./waf docs
238
239 # Only tutorials in `build/docs`
240 ./waf sphinx
241
242 # Only API docs in `build/docs/doxygen`
Sepehr Abdous4fc6db22018-08-22 15:26:06 -0700243 ./waf doxygen
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700244
245Manpages are automatically created and installed during the normal build
246process (e.g., during ``./waf`` and ``./waf install``), if
247``python-sphinx`` module is detected during ``./waf configure`` stage.
248By default, manpages are installed into ``${PREFIX}/share/man`` (where
249default value for ``PREFIX`` is ``/usr/local``). This location can be
250changed during ``./waf configure`` stage using ``--prefix``,
251``--datarootdir``, or ``--mandir`` options.
252
253For more details, refer to ``./waf --help``.
254
Davide Pesavento534b8412018-12-08 19:19:09 -0500255
256Development build
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700257-----------------
258
Davide Pesavento534b8412018-12-08 19:19:09 -0500259The following is the suggested configure command for development builds::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700260
261 ./waf configure --debug --with-tests
262 ./waf
263 sudo ./waf install
Davide Pesavento534b8412018-12-08 19:19:09 -0500264 sudo ldconfig # (on Linux only)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700265
Davide Pesavento534b8412018-12-08 19:19:09 -0500266In the development build most compiler optimizations are disabled by
267default and all warnings are treated as errors. The default behavior can
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700268be overridden by setting ``CXXFLAGS`` environment variable before
Davide Pesavento534b8412018-12-08 19:19:09 -0500269running ``./waf configure``::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700270
271 CXXFLAGS="-O1 -g3" ./waf configure --debug --with-tests
272 ...
Alexander Afanasyev5946ed12015-01-19 23:41:39 -0800273
Alexander Afanasyev5946ed12015-01-19 23:41:39 -0800274
Davide Pesavento534b8412018-12-08 19:19:09 -0500275Customizing the compiler
276------------------------
277
278To choose a custom C++ compiler for building ndn-cxx, set the ``CXX`` environment
Davide Pesavento0530b5b2016-11-07 03:23:58 +0100279variable to point to the compiler binary. For example, to build with clang on
Davide Pesavento534b8412018-12-08 19:19:09 -0500280Linux, use the following::
Alexander Afanasyev5946ed12015-01-19 23:41:39 -0800281
Davide Pesavento0530b5b2016-11-07 03:23:58 +0100282 CXX=clang++ ./waf configure