blob: d1493dd4211450e2f0834c36cf2cd46047a2d9a8 [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 Pesavento81de5d92022-12-30 01:08:05 -050010- Ubuntu 18.04 / 20.04 / 22.04
Davide Pesaventof6625002022-07-31 17:15:02 -040011- Debian 11
12- CentOS Stream 9
Davide Pesavento81de5d92022-12-30 01:08:05 -050013- macOS 10.15 / 11 / 12 / 13
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070014
15ndn-cxx is known to work on the following platforms, although they are not officially
16supported:
17
Davide Pesaventof6625002022-07-31 17:15:02 -040018- Alpine >= 3.12
19- Fedora >= 29
20- Gentoo Linux
21- Raspberry Pi OS (formerly Raspbian) >= 2019-06-20
Davide Pesaventoea5ce492022-09-30 20:25:25 -040022- FreeBSD >= 12.2
Davide Pesavento534b8412018-12-08 19:19:09 -050023
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070024Prerequisites
25-------------
26
Davide Pesaventoab7300b2020-04-09 00:51:41 -040027Required
28~~~~~~~~
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070029
Davide Pesaventof6625002022-07-31 17:15:02 -040030- GCC >= 7.4 or clang >= 6.0 (if you are on Linux or FreeBSD)
31- Xcode >= 11.3 or corresponding version of Command Line Tools (if you are on macOS)
32- Python >= 3.6
33- pkg-config
34- Boost >= 1.65.1
35- OpenSSL >= 1.1.1
36- SQLite 3.x
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070037
Davide Pesaventoab7300b2020-04-09 00:51:41 -040038To build ndn-cxx from source, one must first install a C++ compiler and all necessary
39development tools and libraries:
Davide Pesaventod776a932020-03-20 18:42:36 -040040
Davide Pesavento87208f92022-08-30 19:51:23 -040041- On **Debian** and **Ubuntu**
Davide Pesaventod776a932020-03-20 18:42:36 -040042
43 In a terminal, enter::
44
Davide Pesavento30ed6282021-07-25 20:05:06 -040045 sudo apt install build-essential pkg-config python3-minimal libboost-all-dev libssl-dev libsqlite3-dev
Davide Pesaventod776a932020-03-20 18:42:36 -040046
Davide Pesavento933a5672020-07-03 22:32:43 -040047- On **CentOS** and **Fedora**
Davide Pesaventod776a932020-03-20 18:42:36 -040048
49 In a terminal, enter::
50
Davide Pesavento2349e282020-03-24 14:28:03 -040051 sudo dnf install gcc-c++ pkgconf-pkg-config python3 boost-devel openssl-devel sqlite-devel
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070052
Davide Pesavento933a5672020-07-03 22:32:43 -040053- On **macOS**
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070054
Davide Pesaventod776a932020-03-20 18:42:36 -040055 * Install either Xcode (from the App Store) or the Command Line Tools
56 (with ``xcode-select --install``)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070057
Davide Pesaventocad94b02021-04-09 21:23:03 -040058 * If using Homebrew (recommended), enter the following in a terminal:
59
60 .. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070061
Davide Pesavento534b8412018-12-08 19:19:09 -050062 brew install boost openssl pkg-config
Davide Pesaventocad94b02021-04-09 21:23:03 -040063 brew install python # only on macOS 10.14 and earlier
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070064
Davide Pesavento933a5672020-07-03 22:32:43 -040065 .. warning::
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070066
Davide Pesavento534b8412018-12-08 19:19:09 -050067 If a major OS upgrade is performed after installing the dependencies
68 with Homebrew, remember to reinstall all packages.
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070069
Davide Pesavento933a5672020-07-03 22:32:43 -040070- On **FreeBSD**
Davide Pesavento534b8412018-12-08 19:19:09 -050071
72 In a terminal, enter::
73
Davide Pesaventod776a932020-03-20 18:42:36 -040074 sudo pkg install pkgconf python3 boost-libs openssl sqlite3
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070075
Davide Pesaventoab7300b2020-04-09 00:51:41 -040076Optional
77~~~~~~~~
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070078
Davide Pesavento01cea502021-07-31 19:25:42 -040079To build tutorials, man pages, and API documentation the following additional dependencies
Davide Pesaventoab7300b2020-04-09 00:51:41 -040080need to be installed:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070081
Davide Pesaventof6625002022-07-31 17:15:02 -040082- doxygen
83- graphviz
Davide Pesavento02bbfa72022-09-21 20:53:03 -040084- sphinx >= 4.0
Davide Pesaventof6625002022-07-31 17:15:02 -040085- sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070086
Davide Pesaventod776a932020-03-20 18:42:36 -040087The following lists the steps to install these prerequisites on various common platforms.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070088
Davide Pesavento3ffae262021-08-27 18:48:22 -040089.. note::
90 On Linux, you may need to add ``$HOME/.local/bin`` to the ``PATH`` environment variable
91 for your user, for example:
92
93 .. code-block:: sh
94
95 export PATH="${HOME}/.local/bin${PATH:+:}${PATH}"
96
Davide Pesavento87208f92022-08-30 19:51:23 -040097- On **Debian** and **Ubuntu**:
Davide Pesavento933a5672020-07-03 22:32:43 -040098
99 .. code-block:: sh
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700100
Davide Pesavento534b8412018-12-08 19:19:09 -0500101 sudo apt install doxygen graphviz python3-pip
Davide Pesavento30ed6282021-07-25 20:05:06 -0400102 pip3 install --user sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700103
Davide Pesavento933a5672020-07-03 22:32:43 -0400104- On **CentOS** and **Fedora**:
105
106 .. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700107
Davide Pesavento2349e282020-03-24 14:28:03 -0400108 sudo dnf install doxygen graphviz python3-pip
109 pip3 install --user sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700110
Davide Pesavento933a5672020-07-03 22:32:43 -0400111- On **macOS**:
112
113 .. code-block:: sh
Davide Pesaventod776a932020-03-20 18:42:36 -0400114
115 brew install doxygen graphviz
Davide Pesavento30ed6282021-07-25 20:05:06 -0400116 sudo pip3 install sphinx sphinxcontrib-doxylink
Davide Pesaventod776a932020-03-20 18:42:36 -0400117
Davide Pesavento933a5672020-07-03 22:32:43 -0400118- On **FreeBSD**:
119
120 .. code-block:: sh
Davide Pesavento534b8412018-12-08 19:19:09 -0500121
Davide Pesaventoea5ce492022-09-30 20:25:25 -0400122 sudo pkg install doxygen graphviz py39-sphinx
Davide Pesavento534b8412018-12-08 19:19:09 -0500123
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700124Build
125-----
126
Davide Pesavento534b8412018-12-08 19:19:09 -0500127.. note::
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400128 These are instructions for regular builds of ndn-cxx (release mode). If you are
129 planning to develop the ndn-cxx code itself, you should do a :ref:`Development build`.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700130
Davide Pesavento933a5672020-07-03 22:32:43 -0400131To build in a terminal, change directory to the ndn-cxx root, then enter:
132
133.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700134
Davide Pesaventofbca6112022-07-03 16:31:04 -0400135 ./waf configure
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700136 ./waf
137 sudo ./waf install
138
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400139By default, only the shared variant of the ndn-cxx library will be built. To build the
Davide Pesavento933a5672020-07-03 22:32:43 -0400140static library, pass ``--enable-static`` to the ``./waf configure`` command:
141
142.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700143
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700144 ./waf configure --enable-static
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700145
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400146To disable the build of the shared library and build only the static library, use the
147additional ``--disable-shared`` option. Note that at least one variant of the library
148needs to be enabled.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700149
Davide Pesavento933a5672020-07-03 22:32:43 -0400150.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700151
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700152 ./waf configure --enable-static --disable-shared
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700153
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400154On Linux, it is necessary to run the following command after the shared library has
Davide Pesavento933a5672020-07-03 22:32:43 -0400155been installed:
156
157.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700158
Davide Pesavento534b8412018-12-08 19:19:09 -0500159 sudo ldconfig
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700160
Davide Pesavento534b8412018-12-08 19:19:09 -0500161.. note::
Davide Pesaventofbca6112022-07-03 16:31:04 -0400162 When the library is installed in a non-default location (in general: not in ``/usr/lib``
163 or ``/usr/local/lib``; on some Linux distros like Fedora and its derivatives, including
164 CentOS: not in ``/usr/lib``), the following additional actions may be necessary.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700165
Davide Pesaventofbca6112022-07-03 16:31:04 -0400166 The library installation path should be added to ``/etc/ld.so.conf`` or in
167 ``/etc/ld.so.conf.d/*.conf`` **before** running ``ldconfig``. For example:
Davide Pesavento933a5672020-07-03 22:32:43 -0400168
169 .. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700170
Davide Pesavento534b8412018-12-08 19:19:09 -0500171 echo /usr/local/lib | sudo tee /etc/ld.so.conf.d/ndn-cxx.conf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700172
Davide Pesavento534b8412018-12-08 19:19:09 -0500173 Alternatively, the ``LD_LIBRARY_PATH`` environment variable can be set to point to
Davide Pesavento933a5672020-07-03 22:32:43 -0400174 the installation directory of the shared library:
175
176 .. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700177
Davide Pesavento534b8412018-12-08 19:19:09 -0500178 export LD_LIBRARY_PATH=/usr/local/lib
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700179
Davide Pesavento534b8412018-12-08 19:19:09 -0500180The ``./waf install`` command installs the following files:
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700181
Davide Pesavento534b8412018-12-08 19:19:09 -0500182- ``<LIBPATH>/libndn-cxx.a``: static NDN C++ library (if enabled).
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700183- ``<LIBPATH>/libndn-cxx.so``, ``<LIBPATH>/libndn-cxx.so.<VERSION>`` (on Linux),
Davide Pesavento534b8412018-12-08 19:19:09 -0500184 ``<LIBPATH>/libndn-cxx.dylib``, ``<LIBPATH>/libndn-cxx.<VERSION>.dylib`` (on macOS):
185 shared NDN C++ library (if enabled).
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400186- ``<LIBPATH>/pkgconfig/libndn-cxx.pc``: pkgconfig file storing all necessary flags to
187 build against the library. For example, if the ``pkg-config`` or ``pkgconf-pkg-config``
188 package is installed and ``PKG_CONFIG_PATH`` is configured properly (or if
189 ``<LIBPATH>/pkgconfig`` is a default search path), the command ``pkg-config --cflags
190 --libs libndn-cxx`` will return all necessary compile and link flags for the library.
Davide Pesavento576c21b2022-11-29 20:00:22 -0500191- ``<BINPATH>/ndnsec``: command-line tool to manage NDN keys and certificates.
Davide Pesavento534b8412018-12-08 19:19:09 -0500192- ``<BINPATH>/ndnsec-*``: convenience aliases for ``ndnsec`` tools.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700193
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400194If configured with tests (``./waf configure --with-tests``), the above commands
195will also produce:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700196
Davide Pesavento534b8412018-12-08 19:19:09 -0500197- ``build/unit-tests``: a unit test binary for the library.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700198
Davide Pesaventoab7300b2020-04-09 00:51:41 -04001991.5 GB available memory per CPU core is necessary for efficient compilation. On a
200multi-core machine with less than 1.5 GB available memory per CPU core, limit the
201objects being compiled in parallel with ``./waf -jN``, where N is the amount of
202available memory divided by 1.5 GB (e.g., ``./waf -j2`` for 3 GB of memory). This
203should avoid memory thrashing and result in faster compilation.
Junxiao Shie04bd832014-11-29 23:02:38 -0700204
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700205Build with examples
206-------------------
207
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400208By default, the examples in the ``examples/`` directory will not be built. To enable
Davide Pesavento933a5672020-07-03 22:32:43 -0400209them, pass ``--with-examples`` during the configuration step:
210
211.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700212
Davide Pesaventofbca6112022-07-03 16:31:04 -0400213 ./waf configure --with-examples
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700214 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700215 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400216 sudo ldconfig # on Linux only
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700217
Davide Pesavento933a5672020-07-03 22:32:43 -0400218To run the examples:
219
220.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700221
222 # trivial producer app
223 ./build/examples/producer
224
225 # trivial consumer app
226 ./build/examples/consumer
227
228 # trivial consumer app with timers
229 ./build/examples/consumer-with-timer
230
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400231If you want to make a new sample application, just create a ``.cpp`` file inside the
Davide Pesavento933a5672020-07-03 22:32:43 -0400232``examples/`` directory and it will be compiled during the next run of ``./waf``:
233
234.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700235
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400236 cp examples/consumer.cpp examples/my-new-app.cpp
237 ... # edit examples/my-new-app.cpp with your preferred editor
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700238 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700239 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400240 sudo ldconfig # on Linux only
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400241 ./build/examples/my-new-app
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700242
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700243Debug symbols
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400244-------------
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700245
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400246The default compiler flags include debug symbols in binaries. This should provide
247more meaningful debugging information if ndn-cxx or your application crashes.
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700248
Eric Newberrybdfb53a2020-10-01 10:43:46 -0700249If this is not desired, the default flags can be overridden to disable debug symbols.
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400250The following example shows how to completely disable debug symbols and configure
251ndn-cxx to be installed into ``/usr`` with configuration in the ``/etc`` directory.
252
Davide Pesavento933a5672020-07-03 22:32:43 -0400253.. code-block:: sh
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700254
255 CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc
256 ./waf
257 sudo ./waf install
258
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400259Customizing the compiler
260------------------------
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700261
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400262To build ndn-cxx with a different compiler (rather than the platform default), set the
263``CXX`` environment variable to point to the compiler binary. For example, to build
Davide Pesavento933a5672020-07-03 22:32:43 -0400264with clang on Linux, use the following:
265
266.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700267
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400268 CXX=clang++ ./waf configure
269
270Building the documentation
271--------------------------
272
Eric Newberrybdfb53a2020-10-01 10:43:46 -0700273Tutorials and API documentation can be built using the following commands:
Davide Pesavento933a5672020-07-03 22:32:43 -0400274
275.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700276
277 # Full set of documentation (tutorials + API) in build/docs
278 ./waf docs
279
Davide Pesavento2349e282020-03-24 14:28:03 -0400280 # Only tutorials in build/docs
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700281 ./waf sphinx
282
Davide Pesavento2349e282020-03-24 14:28:03 -0400283 # Only API docs in build/docs/doxygen
Sepehr Abdous4fc6db22018-08-22 15:26:06 -0700284 ./waf doxygen
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700285
Davide Pesavento01cea502021-07-31 19:25:42 -0400286If ``sphinx-build`` is detected during ``./waf configure``, man pages will automatically
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400287be built and installed during the normal build process (i.e., during ``./waf`` and
Davide Pesavento01cea502021-07-31 19:25:42 -0400288``./waf install``). By default, man pages will be installed into ``${PREFIX}/share/man``
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400289(the default value for ``PREFIX`` is ``/usr/local``). This location can be changed
290during the ``./waf configure`` stage using the ``--prefix``, ``--datarootdir``, or
291``--mandir`` options.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700292
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400293For further details, please refer to ``./waf --help``.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700294
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400295.. _Development build:
Davide Pesavento534b8412018-12-08 19:19:09 -0500296
297Development build
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700298-----------------
299
Davide Pesavento933a5672020-07-03 22:32:43 -0400300The following is the suggested build procedure for development builds:
301
302.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700303
Davide Pesaventofbca6112022-07-03 16:31:04 -0400304 ./waf configure --debug --with-tests
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700305 ./waf
306 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400307 sudo ldconfig # on Linux only
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700308
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400309In a development build, most compiler optimizations will be disabled and all warnings
310will be treated as errors. This default behavior can be overridden by setting the
Davide Pesavento933a5672020-07-03 22:32:43 -0400311``CXXFLAGS`` environment variable before running ``./waf configure``, for example:
312
313.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700314
Davide Pesavento81de5d92022-12-30 01:08:05 -0500315 CXXFLAGS="-O1 -g3 -Wall" ./waf configure --debug --with-tests
316 ./waf