blob: 32f479c00bc1841fd10fddf89625a89502e3b020 [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 Pesavento762548b2023-03-05 11:02:02 -050010- Ubuntu 20.04 (focal)
11- Ubuntu 22.04 (jammy)
12- Debian 11 (bullseye)
Davide Pesaventof6625002022-07-31 17:15:02 -040013- CentOS Stream 9
Davide Pesavento762548b2023-03-05 11:02:02 -050014- macOS 11 / 12 / 13
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070015
Davide Pesavento762548b2023-03-05 11:02:02 -050016ndn-cxx should also work on the following platforms, although they are not officially
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070017supported:
18
Davide Pesavento762548b2023-03-05 11:02:02 -050019- Any other recent version of Ubuntu not listed above
Davide Pesaventof6625002022-07-31 17:15:02 -040020- Alpine >= 3.12
Davide Pesavento762548b2023-03-05 11:02:02 -050021- Fedora >= 32
22- Any version of Raspberry Pi OS based on Debian 11 (bullseye)
23- macOS 10.15
Davide Pesaventoea5ce492022-09-30 20:25:25 -040024- FreeBSD >= 12.2
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 Pesavento762548b2023-03-05 11:02:02 -050032- GCC >= 9.3 or clang >= 7.0 (if you are on Linux or FreeBSD)
33- Xcode >= 12.4 or corresponding version of Command Line Tools (if you are on macOS)
34- Python >= 3.8
Davide Pesaventof6625002022-07-31 17:15:02 -040035- pkg-config
36- Boost >= 1.65.1
37- OpenSSL >= 1.1.1
38- 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 Pesavento87208f92022-08-30 19:51:23 -040043- On **Debian** and **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
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070065
Davide Pesavento933a5672020-07-03 22:32:43 -040066 .. warning::
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 Pesavento933a5672020-07-03 22:32:43 -040071- On **FreeBSD**
Davide Pesavento534b8412018-12-08 19:19:09 -050072
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
Davide Pesaventoab7300b2020-04-09 00:51:41 -040077Optional
78~~~~~~~~
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070079
Davide Pesavento01cea502021-07-31 19:25:42 -040080To build tutorials, man pages, and API documentation the following additional dependencies
Davide Pesaventoab7300b2020-04-09 00:51:41 -040081need to be installed:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070082
Davide Pesaventof6625002022-07-31 17:15:02 -040083- doxygen
84- graphviz
Davide Pesavento02bbfa72022-09-21 20:53:03 -040085- sphinx >= 4.0
Davide Pesaventof6625002022-07-31 17:15:02 -040086- 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 Pesavento3ffae262021-08-27 18:48:22 -040090.. note::
91 On Linux, you may need to add ``$HOME/.local/bin`` to the ``PATH`` environment variable
92 for your user, for example:
93
94 .. code-block:: sh
95
96 export PATH="${HOME}/.local/bin${PATH:+:}${PATH}"
97
Davide Pesavento87208f92022-08-30 19:51:23 -040098- On **Debian** and **Ubuntu**:
Davide Pesavento933a5672020-07-03 22:32:43 -040099
100 .. code-block:: sh
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700101
Davide Pesavento534b8412018-12-08 19:19:09 -0500102 sudo apt install doxygen graphviz python3-pip
Davide Pesavento30ed6282021-07-25 20:05:06 -0400103 pip3 install --user sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700104
Davide Pesavento933a5672020-07-03 22:32:43 -0400105- On **CentOS** and **Fedora**:
106
107 .. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700108
Davide Pesavento2349e282020-03-24 14:28:03 -0400109 sudo dnf install doxygen graphviz python3-pip
110 pip3 install --user sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700111
Davide Pesavento933a5672020-07-03 22:32:43 -0400112- On **macOS**:
113
114 .. code-block:: sh
Davide Pesaventod776a932020-03-20 18:42:36 -0400115
116 brew install doxygen graphviz
Davide Pesavento30ed6282021-07-25 20:05:06 -0400117 sudo pip3 install sphinx sphinxcontrib-doxylink
Davide Pesaventod776a932020-03-20 18:42:36 -0400118
Davide Pesavento933a5672020-07-03 22:32:43 -0400119- On **FreeBSD**:
120
121 .. code-block:: sh
Davide Pesavento534b8412018-12-08 19:19:09 -0500122
Davide Pesaventoea5ce492022-09-30 20:25:25 -0400123 sudo pkg install doxygen graphviz py39-sphinx
Davide Pesavento534b8412018-12-08 19:19:09 -0500124
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700125Build
126-----
127
Davide Pesavento534b8412018-12-08 19:19:09 -0500128.. note::
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400129 These are instructions for regular builds of ndn-cxx (release mode). If you are
130 planning to develop the ndn-cxx code itself, you should do a :ref:`Development build`.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700131
Davide Pesavento933a5672020-07-03 22:32:43 -0400132To build in a terminal, change directory to the ndn-cxx root, then enter:
133
134.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700135
Davide Pesaventofbca6112022-07-03 16:31:04 -0400136 ./waf configure
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700137 ./waf
138 sudo ./waf install
139
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400140By default, only the shared variant of the ndn-cxx library will be built. To build the
Davide Pesavento933a5672020-07-03 22:32:43 -0400141static library, pass ``--enable-static`` to the ``./waf configure`` command:
142
143.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700144
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700145 ./waf configure --enable-static
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700146
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400147To disable the build of the shared library and build only the static library, use the
148additional ``--disable-shared`` option. Note that at least one variant of the library
149needs to be enabled.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700150
Davide Pesavento933a5672020-07-03 22:32:43 -0400151.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700152
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700153 ./waf configure --enable-static --disable-shared
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700154
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400155On Linux, it is necessary to run the following command after the shared library has
Davide Pesavento933a5672020-07-03 22:32:43 -0400156been installed:
157
158.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700159
Davide Pesavento534b8412018-12-08 19:19:09 -0500160 sudo ldconfig
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700161
Davide Pesavento534b8412018-12-08 19:19:09 -0500162.. note::
Davide Pesaventofbca6112022-07-03 16:31:04 -0400163 When the library is installed in a non-default location (in general: not in ``/usr/lib``
164 or ``/usr/local/lib``; on some Linux distros like Fedora and its derivatives, including
165 CentOS: not in ``/usr/lib``), the following additional actions may be necessary.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700166
Davide Pesaventofbca6112022-07-03 16:31:04 -0400167 The library installation path should be added to ``/etc/ld.so.conf`` or in
168 ``/etc/ld.so.conf.d/*.conf`` **before** running ``ldconfig``. For example:
Davide Pesavento933a5672020-07-03 22:32:43 -0400169
170 .. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700171
Davide Pesavento534b8412018-12-08 19:19:09 -0500172 echo /usr/local/lib | sudo tee /etc/ld.so.conf.d/ndn-cxx.conf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700173
Davide Pesavento534b8412018-12-08 19:19:09 -0500174 Alternatively, the ``LD_LIBRARY_PATH`` environment variable can be set to point to
Davide Pesavento933a5672020-07-03 22:32:43 -0400175 the installation directory of the shared library:
176
177 .. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700178
Davide Pesavento534b8412018-12-08 19:19:09 -0500179 export LD_LIBRARY_PATH=/usr/local/lib
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700180
Davide Pesavento534b8412018-12-08 19:19:09 -0500181The ``./waf install`` command installs the following files:
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700182
Davide Pesavento534b8412018-12-08 19:19:09 -0500183- ``<LIBPATH>/libndn-cxx.a``: static NDN C++ library (if enabled).
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700184- ``<LIBPATH>/libndn-cxx.so``, ``<LIBPATH>/libndn-cxx.so.<VERSION>`` (on Linux),
Davide Pesavento534b8412018-12-08 19:19:09 -0500185 ``<LIBPATH>/libndn-cxx.dylib``, ``<LIBPATH>/libndn-cxx.<VERSION>.dylib`` (on macOS):
186 shared NDN C++ library (if enabled).
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400187- ``<LIBPATH>/pkgconfig/libndn-cxx.pc``: pkgconfig file storing all necessary flags to
188 build against the library. For example, if the ``pkg-config`` or ``pkgconf-pkg-config``
189 package is installed and ``PKG_CONFIG_PATH`` is configured properly (or if
190 ``<LIBPATH>/pkgconfig`` is a default search path), the command ``pkg-config --cflags
191 --libs libndn-cxx`` will return all necessary compile and link flags for the library.
Davide Pesavento576c21b2022-11-29 20:00:22 -0500192- ``<BINPATH>/ndnsec``: command-line tool to manage NDN keys and certificates.
Davide Pesavento534b8412018-12-08 19:19:09 -0500193- ``<BINPATH>/ndnsec-*``: convenience aliases for ``ndnsec`` tools.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700194
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400195If configured with tests (``./waf configure --with-tests``), the above commands
196will also produce:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700197
Davide Pesavento534b8412018-12-08 19:19:09 -0500198- ``build/unit-tests``: a unit test binary for the library.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700199
Davide Pesaventoab7300b2020-04-09 00:51:41 -04002001.5 GB available memory per CPU core is necessary for efficient compilation. On a
201multi-core machine with less than 1.5 GB available memory per CPU core, limit the
202objects being compiled in parallel with ``./waf -jN``, where N is the amount of
203available memory divided by 1.5 GB (e.g., ``./waf -j2`` for 3 GB of memory). This
204should avoid memory thrashing and result in faster compilation.
Junxiao Shie04bd832014-11-29 23:02:38 -0700205
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700206Build with examples
207-------------------
208
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400209By default, the examples in the ``examples/`` directory will not be built. To enable
Davide Pesavento933a5672020-07-03 22:32:43 -0400210them, pass ``--with-examples`` during the configuration step:
211
212.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700213
Davide Pesaventofbca6112022-07-03 16:31:04 -0400214 ./waf configure --with-examples
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700215 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700216 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400217 sudo ldconfig # on Linux only
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700218
Davide Pesavento933a5672020-07-03 22:32:43 -0400219To run the examples:
220
221.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700222
223 # trivial producer app
224 ./build/examples/producer
225
226 # trivial consumer app
227 ./build/examples/consumer
228
229 # trivial consumer app with timers
230 ./build/examples/consumer-with-timer
231
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400232If you want to make a new sample application, just create a ``.cpp`` file inside the
Davide Pesavento933a5672020-07-03 22:32:43 -0400233``examples/`` directory and it will be compiled during the next run of ``./waf``:
234
235.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700236
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400237 cp examples/consumer.cpp examples/my-new-app.cpp
238 ... # edit examples/my-new-app.cpp with your preferred editor
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700239 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700240 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400241 sudo ldconfig # on Linux only
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400242 ./build/examples/my-new-app
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700243
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700244Debug symbols
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400245-------------
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700246
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400247The default compiler flags include debug symbols in binaries. This should provide
248more meaningful debugging information if ndn-cxx or your application crashes.
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700249
Eric Newberrybdfb53a2020-10-01 10:43:46 -0700250If this is not desired, the default flags can be overridden to disable debug symbols.
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400251The following example shows how to completely disable debug symbols and configure
252ndn-cxx to be installed into ``/usr`` with configuration in the ``/etc`` directory.
253
Davide Pesavento933a5672020-07-03 22:32:43 -0400254.. code-block:: sh
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700255
256 CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc
257 ./waf
258 sudo ./waf install
259
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400260Customizing the compiler
261------------------------
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700262
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400263To build ndn-cxx with a different compiler (rather than the platform default), set the
264``CXX`` environment variable to point to the compiler binary. For example, to build
Davide Pesavento933a5672020-07-03 22:32:43 -0400265with clang on Linux, use the following:
266
267.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700268
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400269 CXX=clang++ ./waf configure
270
271Building the documentation
272--------------------------
273
Eric Newberrybdfb53a2020-10-01 10:43:46 -0700274Tutorials and API documentation can be built using the following commands:
Davide Pesavento933a5672020-07-03 22:32:43 -0400275
276.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700277
278 # Full set of documentation (tutorials + API) in build/docs
279 ./waf docs
280
Davide Pesavento2349e282020-03-24 14:28:03 -0400281 # Only tutorials in build/docs
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700282 ./waf sphinx
283
Davide Pesavento2349e282020-03-24 14:28:03 -0400284 # Only API docs in build/docs/doxygen
Sepehr Abdous4fc6db22018-08-22 15:26:06 -0700285 ./waf doxygen
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700286
Davide Pesavento01cea502021-07-31 19:25:42 -0400287If ``sphinx-build`` is detected during ``./waf configure``, man pages will automatically
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400288be built and installed during the normal build process (i.e., during ``./waf`` and
Davide Pesavento01cea502021-07-31 19:25:42 -0400289``./waf install``). By default, man pages will be installed into ``${PREFIX}/share/man``
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400290(the default value for ``PREFIX`` is ``/usr/local``). This location can be changed
291during the ``./waf configure`` stage using the ``--prefix``, ``--datarootdir``, or
292``--mandir`` options.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700293
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400294For further details, please refer to ``./waf --help``.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700295
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400296.. _Development build:
Davide Pesavento534b8412018-12-08 19:19:09 -0500297
298Development build
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700299-----------------
300
Davide Pesavento933a5672020-07-03 22:32:43 -0400301The following is the suggested build procedure for development builds:
302
303.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700304
Davide Pesaventofbca6112022-07-03 16:31:04 -0400305 ./waf configure --debug --with-tests
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700306 ./waf
307 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400308 sudo ldconfig # on Linux only
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700309
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400310In a development build, most compiler optimizations will be disabled and all warnings
311will be treated as errors. This default behavior can be overridden by setting the
Davide Pesavento933a5672020-07-03 22:32:43 -0400312``CXXFLAGS`` environment variable before running ``./waf configure``, for example:
313
314.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700315
Davide Pesavento81de5d92022-12-30 01:08:05 -0500316 CXXFLAGS="-O1 -g3 -Wall" ./waf configure --debug --with-tests
317 ./waf