blob: bedf60974c879df03299b1397ce26e151f4d6844 [file] [log] [blame]
Alexander Afanasyevc5452c52014-04-29 17:21:51 -07001Getting started with ndn-cxx
2============================
3
4Supported platforms
5-------------------
6
Davide Pesaventoab7300b2020-04-09 00:51:41 -04007ndn-cxx is built against a continuous integration system and has been tested on the
8following platforms:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -07009
Davide Pesavento2349e282020-03-24 14:28:03 -040010- Ubuntu 18.04 (amd64, armhf, i386)
Davide Pesavento933a5672020-07-03 22:32:43 -040011- Ubuntu 20.04 (amd64)
Eric Newberry935d7fe2017-10-29 15:09:36 -070012- macOS 10.13
Davide Pesavento534b8412018-12-08 19:19:09 -050013- macOS 10.14
Alexander Afanasyevcf8ffd42019-12-29 17:58:53 -080014- macOS 10.15
Davide Pesavento2349e282020-03-24 14:28:03 -040015- CentOS 8
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070016
17ndn-cxx is known to work on the following platforms, although they are not officially
18supported:
19
Davide Pesavento78338c52020-04-20 23:00:02 -040020- Debian 10 (Buster)
Davide Pesavento2349e282020-03-24 14:28:03 -040021- Fedora >= 29
Ivan Yeoba1a4a92015-01-11 00:45:57 -080022- Gentoo Linux
Davide Pesavento78338c52020-04-20 23:00:02 -040023- Raspbian >= 2019-06-20 (Buster)
Davide Pesaventod776a932020-03-20 18:42:36 -040024- FreeBSD >= 11.3
Davide Pesavento534b8412018-12-08 19:19:09 -050025
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070026Prerequisites
27-------------
28
Davide Pesaventoab7300b2020-04-09 00:51:41 -040029Required
30~~~~~~~~
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070031
Davide Pesavento71c622b2020-04-24 01:39:01 -040032- GCC >= 7.4 or clang >= 4.0 (on Linux and FreeBSD)
33- Xcode >= 9.0 (on macOS)
Davide Pesavento78338c52020-04-20 23:00:02 -040034- Python >= 3.6
Davide Pesaventoab7300b2020-04-09 00:51:41 -040035- pkg-config
Davide Pesavento78338c52020-04-20 23:00:02 -040036- Boost >= 1.65.1
Davide Pesavento534b8412018-12-08 19:19:09 -050037- OpenSSL >= 1.0.2
Davide Pesaventod776a932020-03-20 18:42:36 -040038- SQLite 3.x
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070039
Davide Pesaventoab7300b2020-04-09 00:51:41 -040040To build ndn-cxx from source, one must first install a C++ compiler and all necessary
41development tools and libraries:
Davide Pesaventod776a932020-03-20 18:42:36 -040042
Davide Pesavento933a5672020-07-03 22:32:43 -040043- On **Ubuntu**
Davide Pesaventod776a932020-03-20 18:42:36 -040044
45 In a terminal, enter::
46
Davide Pesavento30ed6282021-07-25 20:05:06 -040047 sudo apt install build-essential pkg-config python3-minimal libboost-all-dev libssl-dev libsqlite3-dev
Davide Pesaventod776a932020-03-20 18:42:36 -040048
Davide Pesavento933a5672020-07-03 22:32:43 -040049- On **CentOS** and **Fedora**
Davide Pesaventod776a932020-03-20 18:42:36 -040050
51 In a terminal, enter::
52
Davide Pesavento2349e282020-03-24 14:28:03 -040053 sudo dnf install gcc-c++ pkgconf-pkg-config python3 boost-devel openssl-devel sqlite-devel
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070054
Davide Pesavento933a5672020-07-03 22:32:43 -040055- On **macOS**
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070056
Davide Pesaventod776a932020-03-20 18:42:36 -040057 * Install either Xcode (from the App Store) or the Command Line Tools
58 (with ``xcode-select --install``)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070059
Davide Pesaventocad94b02021-04-09 21:23:03 -040060 * If using Homebrew (recommended), enter the following in a terminal:
61
62 .. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070063
Davide Pesavento534b8412018-12-08 19:19:09 -050064 brew install boost openssl pkg-config
Davide Pesaventocad94b02021-04-09 21:23:03 -040065 brew install python # only on macOS 10.14 and earlier
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070066
Davide Pesavento933a5672020-07-03 22:32:43 -040067 .. warning::
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070068
Davide Pesavento534b8412018-12-08 19:19:09 -050069 If a major OS upgrade is performed after installing the dependencies
70 with Homebrew, remember to reinstall all packages.
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070071
Davide Pesavento933a5672020-07-03 22:32:43 -040072- On **FreeBSD**
Davide Pesavento534b8412018-12-08 19:19:09 -050073
74 In a terminal, enter::
75
Davide Pesaventod776a932020-03-20 18:42:36 -040076 sudo pkg install pkgconf python3 boost-libs openssl sqlite3
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070077
Davide Pesaventoab7300b2020-04-09 00:51:41 -040078Optional
79~~~~~~~~
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070080
Davide Pesaventoab7300b2020-04-09 00:51:41 -040081To build tutorials, manpages, and API documentation the following additional dependencies
82need to be installed:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070083
Davide Pesaventoab7300b2020-04-09 00:51:41 -040084- doxygen
85- graphviz
Davide Pesavento933a5672020-07-03 22:32:43 -040086- sphinx >= 1.3
Davide Pesaventoab7300b2020-04-09 00:51:41 -040087- sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070088
Davide Pesaventod776a932020-03-20 18:42:36 -040089The following lists the steps to install these prerequisites on various common platforms.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070090
Davide Pesavento933a5672020-07-03 22:32:43 -040091- On **Ubuntu**:
92
93 .. code-block:: sh
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -070094
Davide Pesavento534b8412018-12-08 19:19:09 -050095 sudo apt install doxygen graphviz python3-pip
Davide Pesavento30ed6282021-07-25 20:05:06 -040096 pip3 install --user sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070097
Davide Pesavento933a5672020-07-03 22:32:43 -040098- On **CentOS** and **Fedora**:
99
100 .. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700101
Davide Pesaventocad94b02021-04-09 21:23:03 -0400102 sudo dnf config-manager --enable powertools # on CentOS only
Davide Pesavento2349e282020-03-24 14:28:03 -0400103 sudo dnf install doxygen graphviz python3-pip
104 pip3 install --user sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700105
Davide Pesavento933a5672020-07-03 22:32:43 -0400106- On **macOS**:
107
108 .. code-block:: sh
Davide Pesaventod776a932020-03-20 18:42:36 -0400109
110 brew install doxygen graphviz
Davide Pesavento30ed6282021-07-25 20:05:06 -0400111 sudo pip3 install sphinx sphinxcontrib-doxylink
Davide Pesaventod776a932020-03-20 18:42:36 -0400112
Davide Pesavento933a5672020-07-03 22:32:43 -0400113- On **FreeBSD**:
114
115 .. code-block:: sh
Davide Pesavento534b8412018-12-08 19:19:09 -0500116
Davide Pesaventod776a932020-03-20 18:42:36 -0400117 sudo pkg install doxygen graphviz py37-sphinx
Davide Pesavento534b8412018-12-08 19:19:09 -0500118
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700119Build
120-----
121
Davide Pesavento534b8412018-12-08 19:19:09 -0500122.. note::
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400123 These are instructions for regular builds of ndn-cxx (release mode). If you are
124 planning to develop the ndn-cxx code itself, you should do a :ref:`Development build`.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700125
Davide Pesavento933a5672020-07-03 22:32:43 -0400126To build in a terminal, change directory to the ndn-cxx root, then enter:
127
128.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700129
Davide Pesavento2349e282020-03-24 14:28:03 -0400130 ./waf configure # on CentOS, add --without-pch
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700131 ./waf
132 sudo ./waf install
133
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400134By default, only the shared variant of the ndn-cxx library will be built. To build the
Davide Pesavento933a5672020-07-03 22:32:43 -0400135static library, pass ``--enable-static`` to the ``./waf configure`` command:
136
137.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700138
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700139 ./waf configure --enable-static
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700140
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400141To disable the build of the shared library and build only the static library, use the
142additional ``--disable-shared`` option. Note that at least one variant of the library
143needs to be enabled.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700144
Davide Pesavento933a5672020-07-03 22:32:43 -0400145.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700146
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700147 ./waf configure --enable-static --disable-shared
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700148
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400149On Linux, it is necessary to run the following command after the shared library has
Davide Pesavento933a5672020-07-03 22:32:43 -0400150been installed:
151
152.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700153
Davide Pesavento534b8412018-12-08 19:19:09 -0500154 sudo ldconfig
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700155
Davide Pesavento534b8412018-12-08 19:19:09 -0500156.. note::
157 When the library is installed in a non-standard path (in general: not in ``/usr/lib``
158 or ``/usr/local/lib``; on some Linux distros including Fedora: not in ``/usr/lib``),
159 additional actions may be necessary.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700160
Davide Pesavento534b8412018-12-08 19:19:09 -0500161 The installation path should be added to ``/etc/ld.so.conf`` (or in
Davide Pesavento933a5672020-07-03 22:32:43 -0400162 ``/etc/ld.so.conf.d``) **before** running ``sudo ldconfig``. For example:
163
164 .. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700165
Davide Pesavento534b8412018-12-08 19:19:09 -0500166 echo /usr/local/lib | sudo tee /etc/ld.so.conf.d/ndn-cxx.conf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700167
Davide Pesavento534b8412018-12-08 19:19:09 -0500168 Alternatively, the ``LD_LIBRARY_PATH`` environment variable can be set to point to
Davide Pesavento933a5672020-07-03 22:32:43 -0400169 the installation directory of the shared library:
170
171 .. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700172
Davide Pesavento534b8412018-12-08 19:19:09 -0500173 export LD_LIBRARY_PATH=/usr/local/lib
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700174
Davide Pesavento534b8412018-12-08 19:19:09 -0500175The ``./waf install`` command installs the following files:
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700176
Davide Pesavento534b8412018-12-08 19:19:09 -0500177- ``<LIBPATH>/libndn-cxx.a``: static NDN C++ library (if enabled).
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700178- ``<LIBPATH>/libndn-cxx.so``, ``<LIBPATH>/libndn-cxx.so.<VERSION>`` (on Linux),
Davide Pesavento534b8412018-12-08 19:19:09 -0500179 ``<LIBPATH>/libndn-cxx.dylib``, ``<LIBPATH>/libndn-cxx.<VERSION>.dylib`` (on macOS):
180 shared NDN C++ library (if enabled).
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400181- ``<LIBPATH>/pkgconfig/libndn-cxx.pc``: pkgconfig file storing all necessary flags to
182 build against the library. For example, if the ``pkg-config`` or ``pkgconf-pkg-config``
183 package is installed and ``PKG_CONFIG_PATH`` is configured properly (or if
184 ``<LIBPATH>/pkgconfig`` is a default search path), the command ``pkg-config --cflags
185 --libs libndn-cxx`` will return all necessary compile and link flags for the library.
Davide Pesavento534b8412018-12-08 19:19:09 -0500186- ``<BINPATH>/ndnsec``: tool to manage NDN keys and certificates.
187- ``<BINPATH>/ndnsec-*``: convenience aliases for ``ndnsec`` tools.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700188
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400189If configured with tests (``./waf configure --with-tests``), the above commands
190will also produce:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700191
Davide Pesavento534b8412018-12-08 19:19:09 -0500192- ``build/unit-tests``: a unit test binary for the library.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700193
Davide Pesaventoab7300b2020-04-09 00:51:41 -04001941.5 GB available memory per CPU core is necessary for efficient compilation. On a
195multi-core machine with less than 1.5 GB available memory per CPU core, limit the
196objects being compiled in parallel with ``./waf -jN``, where N is the amount of
197available memory divided by 1.5 GB (e.g., ``./waf -j2`` for 3 GB of memory). This
198should avoid memory thrashing and result in faster compilation.
Junxiao Shie04bd832014-11-29 23:02:38 -0700199
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700200Build with examples
201-------------------
202
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400203By default, the examples in the ``examples/`` directory will not be built. To enable
Davide Pesavento933a5672020-07-03 22:32:43 -0400204them, pass ``--with-examples`` during the configuration step:
205
206.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700207
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400208 ./waf configure --with-examples # on CentOS, add --without-pch
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700209 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700210 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400211 sudo ldconfig # on Linux only
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700212
Davide Pesavento933a5672020-07-03 22:32:43 -0400213To run the examples:
214
215.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700216
217 # trivial producer app
218 ./build/examples/producer
219
220 # trivial consumer app
221 ./build/examples/consumer
222
223 # trivial consumer app with timers
224 ./build/examples/consumer-with-timer
225
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400226If you want to make a new sample application, just create a ``.cpp`` file inside the
Davide Pesavento933a5672020-07-03 22:32:43 -0400227``examples/`` directory and it will be compiled during the next run of ``./waf``:
228
229.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700230
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400231 cp examples/consumer.cpp examples/my-new-app.cpp
232 ... # edit examples/my-new-app.cpp with your preferred editor
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700233 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700234 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400235 sudo ldconfig # on Linux only
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400236 ./build/examples/my-new-app
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700237
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700238Debug symbols
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400239-------------
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700240
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400241The default compiler flags include debug symbols in binaries. This should provide
242more meaningful debugging information if ndn-cxx or your application crashes.
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700243
Eric Newberrybdfb53a2020-10-01 10:43:46 -0700244If this is not desired, the default flags can be overridden to disable debug symbols.
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400245The following example shows how to completely disable debug symbols and configure
246ndn-cxx to be installed into ``/usr`` with configuration in the ``/etc`` directory.
247
Davide Pesavento933a5672020-07-03 22:32:43 -0400248.. code-block:: sh
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700249
250 CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc
251 ./waf
252 sudo ./waf install
253
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400254Customizing the compiler
255------------------------
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700256
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400257To build ndn-cxx with a different compiler (rather than the platform default), set the
258``CXX`` environment variable to point to the compiler binary. For example, to build
Davide Pesavento933a5672020-07-03 22:32:43 -0400259with clang on Linux, use the following:
260
261.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700262
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400263 CXX=clang++ ./waf configure
264
265Building the documentation
266--------------------------
267
Eric Newberrybdfb53a2020-10-01 10:43:46 -0700268Tutorials and API documentation can be built using the following commands:
Davide Pesavento933a5672020-07-03 22:32:43 -0400269
270.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700271
272 # Full set of documentation (tutorials + API) in build/docs
273 ./waf docs
274
Davide Pesavento2349e282020-03-24 14:28:03 -0400275 # Only tutorials in build/docs
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700276 ./waf sphinx
277
Davide Pesavento2349e282020-03-24 14:28:03 -0400278 # Only API docs in build/docs/doxygen
Sepehr Abdous4fc6db22018-08-22 15:26:06 -0700279 ./waf doxygen
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700280
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400281If ``sphinx-build`` is detected during ``./waf configure``, manpages will automatically
282be built and installed during the normal build process (i.e., during ``./waf`` and
283``./waf install``). By default, manpages will be installed into ``${PREFIX}/share/man``
284(the default value for ``PREFIX`` is ``/usr/local``). This location can be changed
285during the ``./waf configure`` stage using the ``--prefix``, ``--datarootdir``, or
286``--mandir`` options.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700287
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400288For further details, please refer to ``./waf --help``.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700289
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400290.. _Development build:
Davide Pesavento534b8412018-12-08 19:19:09 -0500291
292Development build
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700293-----------------
294
Davide Pesavento933a5672020-07-03 22:32:43 -0400295The following is the suggested build procedure for development builds:
296
297.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700298
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400299 ./waf configure --debug --with-tests # on CentOS, add --without-pch
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700300 ./waf
301 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400302 sudo ldconfig # on Linux only
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700303
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400304In a development build, most compiler optimizations will be disabled and all warnings
305will be treated as errors. This default behavior can be overridden by setting the
Davide Pesavento933a5672020-07-03 22:32:43 -0400306``CXXFLAGS`` environment variable before running ``./waf configure``, for example:
307
308.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700309
310 CXXFLAGS="-O1 -g3" ./waf configure --debug --with-tests
311 ...