blob: 09711cfeeecd40a6a02f935eda114a3690a46611 [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)
Davide Pesavento2be774b2024-06-07 17:25:31 -040012- Ubuntu 24.04 (noble)
Davide Pesavento762548b2023-03-05 11:02:02 -050013- Debian 11 (bullseye)
Davide Pesaventoe1005da2023-10-31 20:35:02 -040014- Debian 12 (bookworm)
Davide Pesaventof6625002022-07-31 17:15:02 -040015- CentOS Stream 9
Davide Pesavento2be774b2024-06-07 17:25:31 -040016- macOS 12 / 13 / 14
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070017
Davide Pesavento762548b2023-03-05 11:02:02 -050018ndn-cxx should also work on the following platforms, although they are not officially
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070019supported:
20
Davide Pesavento762548b2023-03-05 11:02:02 -050021- Any other recent version of Ubuntu not listed above
Davide Pesaventoe1005da2023-10-31 20:35:02 -040022- Fedora >= 33
Davide Pesaventof6625002022-07-31 17:15:02 -040023- Alpine >= 3.12
Davide Pesaventoe1005da2023-10-31 20:35:02 -040024- Any version of Raspberry Pi OS based on Debian 11 (bullseye) or later
Davide Pesavento2be774b2024-06-07 17:25:31 -040025- macOS >= 10.15
Davide Pesaventoea5ce492022-09-30 20:25:25 -040026- FreeBSD >= 12.2
Davide Pesavento534b8412018-12-08 19:19:09 -050027
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070028Prerequisites
29-------------
30
Davide Pesaventoab7300b2020-04-09 00:51:41 -040031Required
32~~~~~~~~
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070033
Davide Pesavento762548b2023-03-05 11:02:02 -050034- GCC >= 9.3 or clang >= 7.0 (if you are on Linux or FreeBSD)
Davide Pesavento2be774b2024-06-07 17:25:31 -040035- Xcode >= 13.0 or corresponding version of Command Line Tools (if you are on macOS)
Davide Pesavento762548b2023-03-05 11:02:02 -050036- Python >= 3.8
Davide Pesaventof6625002022-07-31 17:15:02 -040037- pkg-config
Davide Pesavento550d8c92023-11-05 01:30:01 -040038- Boost >= 1.71.0
Davide Pesaventof6625002022-07-31 17:15:02 -040039- OpenSSL >= 1.1.1
40- SQLite 3.x
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070041
Davide Pesaventoab7300b2020-04-09 00:51:41 -040042To build ndn-cxx from source, one must first install a C++ compiler and all necessary
43development tools and libraries:
Davide Pesaventod776a932020-03-20 18:42:36 -040044
Davide Pesavento87208f92022-08-30 19:51:23 -040045- On **Debian** and **Ubuntu**
Davide Pesaventod776a932020-03-20 18:42:36 -040046
47 In a terminal, enter::
48
Davide Pesavento2d085392024-03-24 02:12:42 -040049 sudo apt install build-essential libboost-all-dev libssl-dev libsqlite3-dev pkg-config python3
Davide Pesaventod776a932020-03-20 18:42:36 -040050
Davide Pesavento933a5672020-07-03 22:32:43 -040051- On **CentOS** and **Fedora**
Davide Pesaventod776a932020-03-20 18:42:36 -040052
53 In a terminal, enter::
54
Davide Pesavento2d085392024-03-24 02:12:42 -040055 sudo dnf install gcc-c++ boost-devel openssl-devel sqlite-devel pkgconf-pkg-config python3
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070056
Davide Pesavento933a5672020-07-03 22:32:43 -040057- On **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 Pesaventocad94b02021-04-09 21:23:03 -040062 * If using Homebrew (recommended), enter the following in a terminal:
63
64 .. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070065
Davide Pesavento534b8412018-12-08 19:19:09 -050066 brew install boost openssl pkg-config
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070067
Davide Pesavento933a5672020-07-03 22:32:43 -040068 .. warning::
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070069
Davide Pesavento534b8412018-12-08 19:19:09 -050070 If a major OS upgrade is performed after installing the dependencies
71 with Homebrew, remember to reinstall all packages.
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070072
Davide Pesavento933a5672020-07-03 22:32:43 -040073- On **FreeBSD**
Davide Pesavento534b8412018-12-08 19:19:09 -050074
75 In a terminal, enter::
76
Davide Pesavento2d085392024-03-24 02:12:42 -040077 sudo pkg install boost-libs openssl sqlite3 pkgconf python3
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070078
Davide Pesaventoab7300b2020-04-09 00:51:41 -040079Optional
80~~~~~~~~
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070081
Davide Pesavento01cea502021-07-31 19:25:42 -040082To build tutorials, man pages, and API documentation the following additional dependencies
Davide Pesaventoab7300b2020-04-09 00:51:41 -040083need to be installed:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070084
Davide Pesaventof6625002022-07-31 17:15:02 -040085- doxygen
86- graphviz
Davide Pesavento02bbfa72022-09-21 20:53:03 -040087- sphinx >= 4.0
Davide Pesaventof6625002022-07-31 17:15:02 -040088- sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070089
Davide Pesaventod776a932020-03-20 18:42:36 -040090The following lists the steps to install these prerequisites on various common platforms.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070091
Davide Pesavento3ffae262021-08-27 18:48:22 -040092.. note::
93 On Linux, you may need to add ``$HOME/.local/bin`` to the ``PATH`` environment variable
94 for your user, for example:
95
96 .. code-block:: sh
97
98 export PATH="${HOME}/.local/bin${PATH:+:}${PATH}"
99
Davide Pesavento87208f92022-08-30 19:51:23 -0400100- On **Debian** and **Ubuntu**:
Davide Pesavento933a5672020-07-03 22:32:43 -0400101
102 .. code-block:: sh
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700103
Davide Pesavento534b8412018-12-08 19:19:09 -0500104 sudo apt install doxygen graphviz python3-pip
Davide Pesavento30ed6282021-07-25 20:05:06 -0400105 pip3 install --user sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700106
Davide Pesavento933a5672020-07-03 22:32:43 -0400107- On **CentOS** and **Fedora**:
108
109 .. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700110
Davide Pesavento2349e282020-03-24 14:28:03 -0400111 sudo dnf install doxygen graphviz python3-pip
112 pip3 install --user sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700113
Davide Pesavento933a5672020-07-03 22:32:43 -0400114- On **macOS**:
115
116 .. code-block:: sh
Davide Pesaventod776a932020-03-20 18:42:36 -0400117
118 brew install doxygen graphviz
Davide Pesavento30ed6282021-07-25 20:05:06 -0400119 sudo pip3 install sphinx sphinxcontrib-doxylink
Davide Pesaventod776a932020-03-20 18:42:36 -0400120
Davide Pesavento933a5672020-07-03 22:32:43 -0400121- On **FreeBSD**:
122
123 .. code-block:: sh
Davide Pesavento534b8412018-12-08 19:19:09 -0500124
Davide Pesaventoea5ce492022-09-30 20:25:25 -0400125 sudo pkg install doxygen graphviz py39-sphinx
Davide Pesavento534b8412018-12-08 19:19:09 -0500126
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700127Build
128-----
129
Davide Pesavento534b8412018-12-08 19:19:09 -0500130.. note::
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400131 These are instructions for regular builds of ndn-cxx (release mode). If you are
132 planning to develop the ndn-cxx code itself, you should do a :ref:`Development build`.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700133
Davide Pesavento933a5672020-07-03 22:32:43 -0400134To build in a terminal, change directory to the ndn-cxx root, then enter:
135
136.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700137
Davide Pesaventofbca6112022-07-03 16:31:04 -0400138 ./waf configure
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700139 ./waf
140 sudo ./waf install
141
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400142By default, only the shared variant of the ndn-cxx library will be built. To build the
Davide Pesavento933a5672020-07-03 22:32:43 -0400143static library, pass ``--enable-static`` to the ``./waf configure`` command:
144
145.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700146
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700147 ./waf configure --enable-static
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700148
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400149To disable the build of the shared library and build only the static library, use the
150additional ``--disable-shared`` option. Note that at least one variant of the library
151needs to be enabled.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700152
Davide Pesavento933a5672020-07-03 22:32:43 -0400153.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700154
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700155 ./waf configure --enable-static --disable-shared
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700156
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400157On Linux, it is necessary to run the following command after the shared library has
Davide Pesavento933a5672020-07-03 22:32:43 -0400158been installed:
159
160.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700161
Davide Pesavento534b8412018-12-08 19:19:09 -0500162 sudo ldconfig
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700163
Davide Pesavento534b8412018-12-08 19:19:09 -0500164.. note::
Davide Pesavento4dc4b3c2024-02-05 20:05:54 -0500165 On Linux, when the library is installed in a non-default location (generally, not in
166 ``/usr/lib`` or ``/usr/local/lib``), the following additional actions may be necessary.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700167
Davide Pesavento4dc4b3c2024-02-05 20:05:54 -0500168 The library installation path should be added to ``/etc/ld.so.conf`` or to
169 ``/etc/ld.so.conf.d/*.conf`` before running ``ldconfig``. For example:
Davide Pesavento933a5672020-07-03 22:32:43 -0400170
171 .. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700172
Davide Pesavento4dc4b3c2024-02-05 20:05:54 -0500173 echo /usr/local/lib64 | sudo tee /etc/ld.so.conf.d/ndn-cxx.conf
174 sudo ldconfig
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700175
Davide Pesavento534b8412018-12-08 19:19:09 -0500176 Alternatively, the ``LD_LIBRARY_PATH`` environment variable can be set to point to
Davide Pesavento933a5672020-07-03 22:32:43 -0400177 the installation directory of the shared library:
178
179 .. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700180
Davide Pesavento4dc4b3c2024-02-05 20:05:54 -0500181 export LD_LIBRARY_PATH=/usr/local/lib64
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700182
Davide Pesavento534b8412018-12-08 19:19:09 -0500183The ``./waf install`` command installs the following files:
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700184
Davide Pesavento4dc4b3c2024-02-05 20:05:54 -0500185- ``<LIBDIR>/libndn-cxx.a``: static NDN C++ library (if enabled).
186- ``<LIBDIR>/libndn-cxx.so``, ``<LIBDIR>/libndn-cxx.so.<VERSION>`` (on Linux),
187 ``<LIBDIR>/libndn-cxx.dylib``, ``<LIBDIR>/libndn-cxx.<VERSION>.dylib`` (on macOS):
Davide Pesavento534b8412018-12-08 19:19:09 -0500188 shared NDN C++ library (if enabled).
Davide Pesavento4dc4b3c2024-02-05 20:05:54 -0500189- ``<LIBDIR>/pkgconfig/libndn-cxx.pc``: pkgconfig file storing all necessary flags to
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400190 build against the library. For example, if the ``pkg-config`` or ``pkgconf-pkg-config``
191 package is installed and ``PKG_CONFIG_PATH`` is configured properly (or if
Davide Pesavento4dc4b3c2024-02-05 20:05:54 -0500192 ``<LIBDIR>/pkgconfig`` is a default search path), the command ``pkg-config --cflags
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400193 --libs libndn-cxx`` will return all necessary compile and link flags for the library.
Davide Pesavento4dc4b3c2024-02-05 20:05:54 -0500194- ``<BINDIR>/ndnsec``: command-line tool to manage NDN keys and certificates.
195- ``<BINDIR>/ndnsec-*``: convenience aliases for ``ndnsec`` tools.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700196
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400197If configured with tests (``./waf configure --with-tests``), the above commands
198will also produce:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700199
Davide Pesavento534b8412018-12-08 19:19:09 -0500200- ``build/unit-tests``: a unit test binary for the library.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700201
Davide Pesaventoab7300b2020-04-09 00:51:41 -04002021.5 GB available memory per CPU core is necessary for efficient compilation. On a
203multi-core machine with less than 1.5 GB available memory per CPU core, limit the
204objects being compiled in parallel with ``./waf -jN``, where N is the amount of
205available memory divided by 1.5 GB (e.g., ``./waf -j2`` for 3 GB of memory). This
206should avoid memory thrashing and result in faster compilation.
Junxiao Shie04bd832014-11-29 23:02:38 -0700207
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700208Build with examples
209-------------------
210
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400211By default, the examples in the ``examples/`` directory will not be built. To enable
Davide Pesavento933a5672020-07-03 22:32:43 -0400212them, pass ``--with-examples`` during the configuration step:
213
214.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700215
Davide Pesaventofbca6112022-07-03 16:31:04 -0400216 ./waf configure --with-examples
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700217 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700218 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400219 sudo ldconfig # on Linux only
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700220
Davide Pesavento933a5672020-07-03 22:32:43 -0400221To run the examples:
222
223.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700224
225 # trivial producer app
226 ./build/examples/producer
227
228 # trivial consumer app
229 ./build/examples/consumer
230
231 # trivial consumer app with timers
232 ./build/examples/consumer-with-timer
233
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400234If you want to make a new sample application, just create a ``.cpp`` file inside the
Davide Pesavento933a5672020-07-03 22:32:43 -0400235``examples/`` directory and it will be compiled during the next run of ``./waf``:
236
237.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700238
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400239 cp examples/consumer.cpp examples/my-new-app.cpp
240 ... # edit examples/my-new-app.cpp with your preferred editor
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700241 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700242 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400243 sudo ldconfig # on Linux only
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400244 ./build/examples/my-new-app
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700245
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700246Debug symbols
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400247-------------
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700248
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400249The default compiler flags include debug symbols in binaries. This should provide
250more meaningful debugging information if ndn-cxx or your application crashes.
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700251
Eric Newberrybdfb53a2020-10-01 10:43:46 -0700252If this is not desired, the default flags can be overridden to disable debug symbols.
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400253The following example shows how to completely disable debug symbols and configure
254ndn-cxx to be installed into ``/usr`` with configuration in the ``/etc`` directory.
255
Davide Pesavento933a5672020-07-03 22:32:43 -0400256.. code-block:: sh
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700257
258 CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc
259 ./waf
260 sudo ./waf install
261
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400262Customizing the compiler
263------------------------
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700264
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400265To build ndn-cxx with a different compiler (rather than the platform default), set the
266``CXX`` environment variable to point to the compiler binary. For example, to build
Davide Pesavento933a5672020-07-03 22:32:43 -0400267with clang on Linux, use the following:
268
269.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700270
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400271 CXX=clang++ ./waf configure
272
273Building the documentation
274--------------------------
275
Eric Newberrybdfb53a2020-10-01 10:43:46 -0700276Tutorials and API documentation can be built using the following commands:
Davide Pesavento933a5672020-07-03 22:32:43 -0400277
278.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700279
280 # Full set of documentation (tutorials + API) in build/docs
281 ./waf docs
282
Davide Pesavento2349e282020-03-24 14:28:03 -0400283 # Only tutorials in build/docs
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700284 ./waf sphinx
285
Davide Pesavento2349e282020-03-24 14:28:03 -0400286 # Only API docs in build/docs/doxygen
Sepehr Abdous4fc6db22018-08-22 15:26:06 -0700287 ./waf doxygen
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700288
Davide Pesavento01cea502021-07-31 19:25:42 -0400289If ``sphinx-build`` is detected during ``./waf configure``, man pages will automatically
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400290be built and installed during the normal build process (i.e., during ``./waf`` and
Davide Pesavento01cea502021-07-31 19:25:42 -0400291``./waf install``). By default, man pages will be installed into ``${PREFIX}/share/man``
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400292(the default value for ``PREFIX`` is ``/usr/local``). This location can be changed
293during the ``./waf configure`` stage using the ``--prefix``, ``--datarootdir``, or
294``--mandir`` options.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700295
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400296For further details, please refer to ``./waf --help``.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700297
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400298.. _Development build:
Davide Pesavento534b8412018-12-08 19:19:09 -0500299
300Development build
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700301-----------------
302
Davide Pesavento933a5672020-07-03 22:32:43 -0400303The following is the suggested build procedure for development builds:
304
305.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700306
Davide Pesaventofbca6112022-07-03 16:31:04 -0400307 ./waf configure --debug --with-tests
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700308 ./waf
309 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400310 sudo ldconfig # on Linux only
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700311
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400312In a development build, most compiler optimizations will be disabled and all warnings
313will be treated as errors. This default behavior can be overridden by setting the
Davide Pesavento933a5672020-07-03 22:32:43 -0400314``CXXFLAGS`` environment variable before running ``./waf configure``, for example:
315
316.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700317
Davide Pesavento81de5d92022-12-30 01:08:05 -0500318 CXXFLAGS="-O1 -g3 -Wall" ./waf configure --debug --with-tests
319 ./waf