blob: aa43bd63bb50cc3e83e3cc097d7d6ad463710ffe [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 Afanasyevcf8ffd42019-12-29 17:58:53 -080014- Ubuntu 19.10 (amd64)
Eric Newberry935d7fe2017-10-29 15:09:36 -070015- macOS 10.13
Davide Pesavento534b8412018-12-08 19:19:09 -050016- macOS 10.14
Alexander Afanasyevcf8ffd42019-12-29 17:58:53 -080017- macOS 10.15
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 Pesaventod776a932020-03-20 18:42:36 -040027- FreeBSD >= 11.3
Davide Pesavento534b8412018-12-08 19:19:09 -050028
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070029Prerequisites
30-------------
31
32Required:
33~~~~~~~~~
34
Davide Pesaventoca660f12018-06-16 14:01:51 -040035- GCC >= 5.3, or clang >= 3.6
Davide Pesaventod776a932020-03-20 18:42:36 -040036- Python >= 3.5
Davide Pesavento534b8412018-12-08 19:19:09 -050037- ``pkg-config``
Davide Pesaventod776a932020-03-20 18:42:36 -040038- Boost >= 1.58
Davide Pesavento534b8412018-12-08 19:19:09 -050039- OpenSSL >= 1.0.2
Davide Pesaventod776a932020-03-20 18:42:36 -040040- SQLite 3.x
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070041
Davide Pesaventod776a932020-03-20 18:42:36 -040042Following are the detailed steps for each platform to install the compiler and all necessary
43development tools and libraries that are required to build ndn-cxx from source.
44
45- Ubuntu
46
47 In a terminal, enter::
48
49 sudo apt install build-essential pkg-config python3-minimal libboost-all-dev libssl-dev libsqlite3-dev
50
51- Fedora
52
53 In a terminal, enter::
54
55 sudo yum install gcc-g++ boost-devel openssl-devel sqlite-devel
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070056
Davide Pesavento534b8412018-12-08 19:19:09 -050057- macOS
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070058
Davide Pesaventod776a932020-03-20 18:42:36 -040059 * Install either Xcode (from the App Store) or the Command Line Tools
60 (with ``xcode-select --install``)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070061
Davide Pesavento534b8412018-12-08 19:19:09 -050062 * If using Homebrew (recommended), enter the following in a terminal::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070063
Davide Pesavento534b8412018-12-08 19:19:09 -050064 brew install boost openssl pkg-config
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070065
Davide Pesavento534b8412018-12-08 19:19:09 -050066 .. note::
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070067
Davide Pesavento534b8412018-12-08 19:19:09 -050068 If a major OS upgrade is performed after installing the dependencies
69 with Homebrew, remember to reinstall all packages.
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070070
Davide Pesavento534b8412018-12-08 19:19:09 -050071- FreeBSD
72
73 In a terminal, enter::
74
Davide Pesaventod776a932020-03-20 18:42:36 -040075 sudo pkg install pkgconf python3 boost-libs openssl sqlite3
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070076
77Optional:
78~~~~~~~~~
79
80To build tutorials, manpages, and API documentation the following
81dependencies need to be installed:
82
83- ``doxygen``
84- ``graphviz``
Davide Pesaventod776a932020-03-20 18:42:36 -040085- ``sphinx``
Davide Pesavento534b8412018-12-08 19:19:09 -050086- ``sphinxcontrib-doxylink``
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070087
Davide Pesaventod776a932020-03-20 18:42:36 -040088The following lists the steps to install these prerequisites on various common platforms.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070089
Davide Pesavento534b8412018-12-08 19:19:09 -050090- On Ubuntu::
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -070091
Davide Pesavento534b8412018-12-08 19:19:09 -050092 sudo apt install doxygen graphviz python3-pip
93 sudo pip3 install sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070094
Davide Pesavento534b8412018-12-08 19:19:09 -050095- On Fedora::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070096
Davide Pesavento534b8412018-12-08 19:19:09 -050097 sudo yum install doxygen graphviz python-sphinx
98 sudo pip install sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070099
Davide Pesaventod776a932020-03-20 18:42:36 -0400100- On macOS::
101
102 brew install doxygen graphviz
103 sudo pip install sphinx sphinxcontrib-doxylink
104
Davide Pesavento534b8412018-12-08 19:19:09 -0500105- On FreeBSD::
106
Davide Pesaventod776a932020-03-20 18:42:36 -0400107 sudo pkg install doxygen graphviz py37-sphinx
Davide Pesavento534b8412018-12-08 19:19:09 -0500108
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700109
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700110.. _build:
111
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700112Build
113-----
114
Davide Pesavento534b8412018-12-08 19:19:09 -0500115.. note::
116 These are instructions for regular builds of ndn-cxx (release mode).
117 To do development of ndn-cxx code itself, see "Development build" below.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700118
Davide Pesavento534b8412018-12-08 19:19:09 -0500119To build in a terminal, change directory to the ndn-cxx root, then enter::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700120
121 ./waf configure
122 ./waf
123 sudo ./waf install
124
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700125By default, only the shared version of ndn-cxx library is built. To build the static library,
Davide Pesavento534b8412018-12-08 19:19:09 -0500126use ``--enable-static`` option for ``./waf configure`` command::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700127
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700128 ./waf configure --enable-static
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700129
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700130To disable build of the shared library and build only the static library, use additional
131``--disable-shared`` option. Note that at least one version of the library needs to be
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700132enabled.
133
134::
135
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700136 ./waf configure --enable-static --disable-shared
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700137
Davide Pesavento534b8412018-12-08 19:19:09 -0500138After the shared library is installed, on Linux it is also necessary to run::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700139
Davide Pesavento534b8412018-12-08 19:19:09 -0500140 sudo ldconfig
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700141
Davide Pesavento534b8412018-12-08 19:19:09 -0500142.. note::
143 When the library is installed in a non-standard path (in general: not in ``/usr/lib``
144 or ``/usr/local/lib``; on some Linux distros including Fedora: not in ``/usr/lib``),
145 additional actions may be necessary.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700146
Davide Pesavento534b8412018-12-08 19:19:09 -0500147 The installation path should be added to ``/etc/ld.so.conf`` (or in
148 ``/etc/ld.so.conf.d``) **before** running ``sudo ldconfig``. For example::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700149
Davide Pesavento534b8412018-12-08 19:19:09 -0500150 echo /usr/local/lib | sudo tee /etc/ld.so.conf.d/ndn-cxx.conf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700151
Davide Pesavento534b8412018-12-08 19:19:09 -0500152 Alternatively, the ``LD_LIBRARY_PATH`` environment variable can be set to point to
153 the installation directory of the shared library::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700154
Davide Pesavento534b8412018-12-08 19:19:09 -0500155 export LD_LIBRARY_PATH=/usr/local/lib
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700156
Davide Pesavento534b8412018-12-08 19:19:09 -0500157The ``./waf install`` command installs the following files:
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700158
Davide Pesavento534b8412018-12-08 19:19:09 -0500159- ``<LIBPATH>/libndn-cxx.a``: static NDN C++ library (if enabled).
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700160- ``<LIBPATH>/libndn-cxx.so``, ``<LIBPATH>/libndn-cxx.so.<VERSION>`` (on Linux),
Davide Pesavento534b8412018-12-08 19:19:09 -0500161 ``<LIBPATH>/libndn-cxx.dylib``, ``<LIBPATH>/libndn-cxx.<VERSION>.dylib`` (on macOS):
162 shared NDN C++ library (if enabled).
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700163- ``<LIBPATH>/pkgconfig/libndn-cxx.pc``: pkgconfig file storing all
164 neccessary flags to build against the library. For example, if
Davide Pesavento534b8412018-12-08 19:19:09 -0500165 pkg-config or pkgconf package is installed and ``PKG_CONFIG_PATH`` is
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700166 configured properly (or ``<LIBPATH>/pkgconfig`` is a default path),
167 ``pkgconfig --libs --clflags libndn-cxx`` will return all necessary
168 compile and link flags for the library.
Davide Pesavento534b8412018-12-08 19:19:09 -0500169- ``<BINPATH>/ndnsec``: tool to manage NDN keys and certificates.
170- ``<BINPATH>/ndnsec-*``: convenience aliases for ``ndnsec`` tools.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700171
Davide Pesavento534b8412018-12-08 19:19:09 -0500172If configured with tests (``./waf configure --with-tests``), the above
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700173commands will also produce:
174
Davide Pesavento534b8412018-12-08 19:19:09 -0500175- ``build/unit-tests``: a unit test binary for the library.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700176
Junxiao Shie04bd832014-11-29 23:02:38 -07001771.5GB available memory per CPU core is necessary for efficient compilation.
178On a multi-core machine with less than 1.5GB available memory per CPU core,
179limit the objects being compiled in parallel with ``./waf -jN`` where N is the amount
180of available memory divided by 1.5GB (eg. ``./waf -j1`` for 1.5GB memory),
Davide Pesavento534b8412018-12-08 19:19:09 -0500181which should usually avoid memory thrashing and result in faster compilation.
Junxiao Shie04bd832014-11-29 23:02:38 -0700182
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700183Build with examples
184-------------------
185
Davide Pesavento534b8412018-12-08 19:19:09 -0500186By default, examples in ``examples/`` are not built. To enable them, use the
187``--with-examples`` configure option::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700188
189 ./waf configure --with-examples
190 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700191 sudo ./waf install
Davide Pesavento534b8412018-12-08 19:19:09 -0500192 sudo ldconfig # (on Linux only)
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700193
Davide Pesavento534b8412018-12-08 19:19:09 -0500194To run examples::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700195
196 # trivial producer app
197 ./build/examples/producer
198
199 # trivial consumer app
200 ./build/examples/consumer
201
202 # trivial consumer app with timers
203 ./build/examples/consumer-with-timer
204
205If you want to test out a sample application, just create a ``.cpp`` file in ``examples/``
Davide Pesavento534b8412018-12-08 19:19:09 -0500206folder and it will be compiled on the next run on ``./waf``. For example::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700207
208 cp examples/consumer.cpp examples/my-new-consumer-app.cpp
209 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700210 sudo ./waf install
Davide Pesavento534b8412018-12-08 19:19:09 -0500211 sudo ldconfig # (on Linux only)
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700212 ./build/examples/my-new-consumer-app
213
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700214Debug symbols
215~~~~~~~~~~~~~
216
217The default compiler flags enable debug symbols to be included in binaries (i.e., ``-g``
218flag for ``./waf configure`` and ``-g3`` for ``./waf configure --debug``). This
219potentially allows more meaningful debugging information if your application crashes.
220
Davide Pesavento534b8412018-12-08 19:19:09 -0500221The default build flags can easily be overridden::
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700222
223 CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc
224 ./waf
225 sudo ./waf install
226
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700227
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700228Documentation
229-------------
230
231ndn-cxx tutorials and API documentation can be built using the following
Davide Pesavento534b8412018-12-08 19:19:09 -0500232commands::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700233
234 # Full set of documentation (tutorials + API) in build/docs
235 ./waf docs
236
237 # Only tutorials in `build/docs`
238 ./waf sphinx
239
240 # Only API docs in `build/docs/doxygen`
Sepehr Abdous4fc6db22018-08-22 15:26:06 -0700241 ./waf doxygen
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700242
243Manpages are automatically created and installed during the normal build
244process (e.g., during ``./waf`` and ``./waf install``), if
245``python-sphinx`` module is detected during ``./waf configure`` stage.
246By default, manpages are installed into ``${PREFIX}/share/man`` (where
247default value for ``PREFIX`` is ``/usr/local``). This location can be
248changed during ``./waf configure`` stage using ``--prefix``,
249``--datarootdir``, or ``--mandir`` options.
250
251For more details, refer to ``./waf --help``.
252
Davide Pesavento534b8412018-12-08 19:19:09 -0500253
254Development build
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700255-----------------
256
Davide Pesavento534b8412018-12-08 19:19:09 -0500257The following is the suggested configure command for development builds::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700258
259 ./waf configure --debug --with-tests
260 ./waf
261 sudo ./waf install
Davide Pesavento534b8412018-12-08 19:19:09 -0500262 sudo ldconfig # (on Linux only)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700263
Davide Pesavento534b8412018-12-08 19:19:09 -0500264In the development build most compiler optimizations are disabled by
265default and all warnings are treated as errors. The default behavior can
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700266be overridden by setting ``CXXFLAGS`` environment variable before
Davide Pesavento534b8412018-12-08 19:19:09 -0500267running ``./waf configure``::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700268
269 CXXFLAGS="-O1 -g3" ./waf configure --debug --with-tests
270 ...
Alexander Afanasyev5946ed12015-01-19 23:41:39 -0800271
Alexander Afanasyev5946ed12015-01-19 23:41:39 -0800272
Davide Pesavento534b8412018-12-08 19:19:09 -0500273Customizing the compiler
274------------------------
275
276To choose a custom C++ compiler for building ndn-cxx, set the ``CXX`` environment
Davide Pesavento0530b5b2016-11-07 03:23:58 +0100277variable to point to the compiler binary. For example, to build with clang on
Davide Pesavento534b8412018-12-08 19:19:09 -0500278Linux, use the following::
Alexander Afanasyev5946ed12015-01-19 23:41:39 -0800279
Davide Pesavento0530b5b2016-11-07 03:23:58 +0100280 CXX=clang++ ./waf configure