blob: 864bb10a0d880bd8572562bf8118761bf973cfb9 [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)
Davide Pesavento0530b5b2016-11-07 03:23:58 +010014- macOS 10.12
Eric Newberry935d7fe2017-10-29 15:09:36 -070015- macOS 10.13
Davide Pesavento534b8412018-12-08 19:19:09 -050016- macOS 10.14
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070017
18ndn-cxx is known to work on the following platforms, although they are not officially
19supported:
20
Davide Pesavento7c4ad512018-04-28 15:20:11 -040021- Debian >= 9
22- Fedora >= 24
Ivan Yeoba1a4a92015-01-11 00:45:57 -080023- Gentoo Linux
Davide Pesavento7c4ad512018-04-28 15:20:11 -040024- Raspbian >= 2017-08-16
Davide Pesavento534b8412018-12-08 19:19:09 -050025- OS X 10.11
26- FreeBSD 11.2
27
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070028
29Prerequisites
30-------------
31
32Required:
33~~~~~~~~~
34
Davide Pesaventoca660f12018-06-16 14:01:51 -040035- GCC >= 5.3, or clang >= 3.6
Davide Pesavento7c4ad512018-04-28 15:20:11 -040036- ``python2`` >= 2.7, or ``python3`` >= 3.4
Davide Pesavento844b0932018-05-07 01:00:16 -040037- Boost libraries >= 1.58
Davide Pesavento534b8412018-12-08 19:19:09 -050038- ``pkg-config``
39- SQLite 3.x
40- OpenSSL >= 1.0.2
41- Apple Security framework (on macOS only)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070042
43Following are the detailed steps for each platform to install the compiler, all necessary
44development tools and libraries, and ndn-cxx prerequisites.
45
Davide Pesavento534b8412018-12-08 19:19:09 -050046- macOS
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070047
Davide Pesavento534b8412018-12-08 19:19:09 -050048 * Install Xcode from the App Store, or at least the Command Line Tools
49 (``xcode-select --install``)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070050
Davide Pesavento534b8412018-12-08 19:19:09 -050051 * If using Homebrew (recommended), enter the following in a terminal::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070052
Davide Pesavento534b8412018-12-08 19:19:09 -050053 brew install boost openssl pkg-config
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070054
Davide Pesavento534b8412018-12-08 19:19:09 -050055 .. note::
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070056
Davide Pesavento534b8412018-12-08 19:19:09 -050057 If a major OS upgrade is performed after installing the dependencies
58 with Homebrew, remember to reinstall all packages.
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070059
Davide Pesavento534b8412018-12-08 19:19:09 -050060- Ubuntu
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070061
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070062 In a terminal, enter::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070063
Davide Pesavento534b8412018-12-08 19:19:09 -050064 sudo apt install build-essential libsqlite3-dev libboost-all-dev libssl-dev
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070065
Ivan Yeoba1a4a92015-01-11 00:45:57 -080066- Fedora
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070067
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070068 In a terminal, enter::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070069
Davide Pesavento534b8412018-12-08 19:19:09 -050070 sudo yum install gcc-g++ sqlite-devel boost-devel openssl-devel
71
72- FreeBSD
73
74 In a terminal, enter::
75
76 sudo pkg install python pkgconf sqlite3 boost-libs
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070077
78Optional:
79~~~~~~~~~
80
81To build tutorials, manpages, and API documentation the following
82dependencies need to be installed:
83
84- ``doxygen``
85- ``graphviz``
Davide Pesavento534b8412018-12-08 19:19:09 -050086- ``python-sphinx``
87- ``sphinxcontrib-doxylink``
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070088
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -070089The following lists steps for common platforms to install these prerequisites:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070090
Davide Pesavento534b8412018-12-08 19:19:09 -050091- On macOS with Homebrew and pip::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070092
Davide Pesavento534b8412018-12-08 19:19:09 -050093 brew install doxygen graphviz
94 sudo pip install sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070095
Davide Pesavento534b8412018-12-08 19:19:09 -050096- On Ubuntu::
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -070097
Davide Pesavento534b8412018-12-08 19:19:09 -050098 sudo apt install doxygen graphviz python3-pip
99 sudo pip3 install sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700100
Davide Pesavento534b8412018-12-08 19:19:09 -0500101- On Fedora::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700102
Davide Pesavento534b8412018-12-08 19:19:09 -0500103 sudo yum install doxygen graphviz python-sphinx
104 sudo pip install sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700105
Davide Pesavento534b8412018-12-08 19:19:09 -0500106- On FreeBSD::
107
108 sudo pkg install doxygen graphviz py27-sphinx
109
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700110
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700111.. _build:
112
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700113Build
114-----
115
Davide Pesavento534b8412018-12-08 19:19:09 -0500116.. note::
117 These are instructions for regular builds of ndn-cxx (release mode).
118 To do development of ndn-cxx code itself, see "Development build" below.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700119
Davide Pesavento534b8412018-12-08 19:19:09 -0500120To build in a terminal, change directory to the ndn-cxx root, then enter::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700121
122 ./waf configure
123 ./waf
124 sudo ./waf install
125
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700126By default, only the shared version of ndn-cxx library is built. To build the static library,
Davide Pesavento534b8412018-12-08 19:19:09 -0500127use ``--enable-static`` option for ``./waf configure`` command::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700128
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700129 ./waf configure --enable-static
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700130
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700131To disable build of the shared library and build only the static library, use additional
132``--disable-shared`` option. Note that at least one version of the library needs to be
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700133enabled.
134
135::
136
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700137 ./waf configure --enable-static --disable-shared
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700138
Davide Pesavento534b8412018-12-08 19:19:09 -0500139After the shared library is installed, on Linux it is also necessary to run::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700140
Davide Pesavento534b8412018-12-08 19:19:09 -0500141 sudo ldconfig
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700142
Davide Pesavento534b8412018-12-08 19:19:09 -0500143.. note::
144 When the library is installed in a non-standard path (in general: not in ``/usr/lib``
145 or ``/usr/local/lib``; on some Linux distros including Fedora: not in ``/usr/lib``),
146 additional actions may be necessary.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700147
Davide Pesavento534b8412018-12-08 19:19:09 -0500148 The installation path should be added to ``/etc/ld.so.conf`` (or in
149 ``/etc/ld.so.conf.d``) **before** running ``sudo ldconfig``. For example::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700150
Davide Pesavento534b8412018-12-08 19:19:09 -0500151 echo /usr/local/lib | sudo tee /etc/ld.so.conf.d/ndn-cxx.conf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700152
Davide Pesavento534b8412018-12-08 19:19:09 -0500153 Alternatively, the ``LD_LIBRARY_PATH`` environment variable can be set to point to
154 the installation directory of the shared library::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700155
Davide Pesavento534b8412018-12-08 19:19:09 -0500156 export LD_LIBRARY_PATH=/usr/local/lib
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700157
Davide Pesavento534b8412018-12-08 19:19:09 -0500158The ``./waf install`` command installs the following files:
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700159
Davide Pesavento534b8412018-12-08 19:19:09 -0500160- ``<LIBPATH>/libndn-cxx.a``: static NDN C++ library (if enabled).
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700161- ``<LIBPATH>/libndn-cxx.so``, ``<LIBPATH>/libndn-cxx.so.<VERSION>`` (on Linux),
Davide Pesavento534b8412018-12-08 19:19:09 -0500162 ``<LIBPATH>/libndn-cxx.dylib``, ``<LIBPATH>/libndn-cxx.<VERSION>.dylib`` (on macOS):
163 shared NDN C++ library (if enabled).
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700164- ``<LIBPATH>/pkgconfig/libndn-cxx.pc``: pkgconfig file storing all
165 neccessary flags to build against the library. For example, if
Davide Pesavento534b8412018-12-08 19:19:09 -0500166 pkg-config or pkgconf package is installed and ``PKG_CONFIG_PATH`` is
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700167 configured properly (or ``<LIBPATH>/pkgconfig`` is a default path),
168 ``pkgconfig --libs --clflags libndn-cxx`` will return all necessary
169 compile and link flags for the library.
Davide Pesavento534b8412018-12-08 19:19:09 -0500170- ``<BINPATH>/ndnsec``: tool to manage NDN keys and certificates.
171- ``<BINPATH>/ndnsec-*``: convenience aliases for ``ndnsec`` tools.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700172
Davide Pesavento534b8412018-12-08 19:19:09 -0500173If configured with tests (``./waf configure --with-tests``), the above
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700174commands will also produce:
175
Davide Pesavento534b8412018-12-08 19:19:09 -0500176- ``build/unit-tests``: a unit test binary for the library.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700177
Junxiao Shie04bd832014-11-29 23:02:38 -07001781.5GB available memory per CPU core is necessary for efficient compilation.
179On a multi-core machine with less than 1.5GB available memory per CPU core,
180limit the objects being compiled in parallel with ``./waf -jN`` where N is the amount
181of available memory divided by 1.5GB (eg. ``./waf -j1`` for 1.5GB memory),
Davide Pesavento534b8412018-12-08 19:19:09 -0500182which should usually avoid memory thrashing and result in faster compilation.
Junxiao Shie04bd832014-11-29 23:02:38 -0700183
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700184Build with examples
185-------------------
186
Davide Pesavento534b8412018-12-08 19:19:09 -0500187By default, examples in ``examples/`` are not built. To enable them, use the
188``--with-examples`` configure option::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700189
190 ./waf configure --with-examples
191 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700192 sudo ./waf install
Davide Pesavento534b8412018-12-08 19:19:09 -0500193 sudo ldconfig # (on Linux only)
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700194
Davide Pesavento534b8412018-12-08 19:19:09 -0500195To run examples::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700196
197 # trivial producer app
198 ./build/examples/producer
199
200 # trivial consumer app
201 ./build/examples/consumer
202
203 # trivial consumer app with timers
204 ./build/examples/consumer-with-timer
205
206If you want to test out a sample application, just create a ``.cpp`` file in ``examples/``
Davide Pesavento534b8412018-12-08 19:19:09 -0500207folder and it will be compiled on the next run on ``./waf``. For example::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700208
209 cp examples/consumer.cpp examples/my-new-consumer-app.cpp
210 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700211 sudo ./waf install
Davide Pesavento534b8412018-12-08 19:19:09 -0500212 sudo ldconfig # (on Linux only)
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700213 ./build/examples/my-new-consumer-app
214
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700215Debug symbols
216~~~~~~~~~~~~~
217
218The default compiler flags enable debug symbols to be included in binaries (i.e., ``-g``
219flag for ``./waf configure`` and ``-g3`` for ``./waf configure --debug``). This
220potentially allows more meaningful debugging information if your application crashes.
221
Davide Pesavento534b8412018-12-08 19:19:09 -0500222The default build flags can easily be overridden::
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700223
224 CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc
225 ./waf
226 sudo ./waf install
227
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700228
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700229Documentation
230-------------
231
232ndn-cxx tutorials and API documentation can be built using the following
Davide Pesavento534b8412018-12-08 19:19:09 -0500233commands::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700234
235 # Full set of documentation (tutorials + API) in build/docs
236 ./waf docs
237
238 # Only tutorials in `build/docs`
239 ./waf sphinx
240
241 # Only API docs in `build/docs/doxygen`
Sepehr Abdous4fc6db22018-08-22 15:26:06 -0700242 ./waf doxygen
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700243
244Manpages are automatically created and installed during the normal build
245process (e.g., during ``./waf`` and ``./waf install``), if
246``python-sphinx`` module is detected during ``./waf configure`` stage.
247By default, manpages are installed into ``${PREFIX}/share/man`` (where
248default value for ``PREFIX`` is ``/usr/local``). This location can be
249changed during ``./waf configure`` stage using ``--prefix``,
250``--datarootdir``, or ``--mandir`` options.
251
252For more details, refer to ``./waf --help``.
253
Davide Pesavento534b8412018-12-08 19:19:09 -0500254
255Development build
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700256-----------------
257
Davide Pesavento534b8412018-12-08 19:19:09 -0500258The following is the suggested configure command for development builds::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700259
260 ./waf configure --debug --with-tests
261 ./waf
262 sudo ./waf install
Davide Pesavento534b8412018-12-08 19:19:09 -0500263 sudo ldconfig # (on Linux only)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700264
Davide Pesavento534b8412018-12-08 19:19:09 -0500265In the development build most compiler optimizations are disabled by
266default and all warnings are treated as errors. The default behavior can
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700267be overridden by setting ``CXXFLAGS`` environment variable before
Davide Pesavento534b8412018-12-08 19:19:09 -0500268running ``./waf configure``::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700269
270 CXXFLAGS="-O1 -g3" ./waf configure --debug --with-tests
271 ...
Alexander Afanasyev5946ed12015-01-19 23:41:39 -0800272
Alexander Afanasyev5946ed12015-01-19 23:41:39 -0800273
Davide Pesavento534b8412018-12-08 19:19:09 -0500274Customizing the compiler
275------------------------
276
277To choose a custom C++ compiler for building ndn-cxx, set the ``CXX`` environment
Davide Pesavento0530b5b2016-11-07 03:23:58 +0100278variable to point to the compiler binary. For example, to build with clang on
Davide Pesavento534b8412018-12-08 19:19:09 -0500279Linux, use the following::
Alexander Afanasyev5946ed12015-01-19 23:41:39 -0800280
Davide Pesavento0530b5b2016-11-07 03:23:58 +0100281 CXX=clang++ ./waf configure