blob: 7c90deb55972f588719d05badb007a958f063d6e [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)
Davide Pesavento3ffae262021-08-27 18:48:22 -040012- Ubuntu 21.04 (amd64)
Alexander Afanasyevcf8ffd42019-12-29 17:58:53 -080013- macOS 10.15
Davide Pesavento83f8d162021-09-26 21:58:36 -040014- macOS 11 (Intel only)
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 Pesavento3ffae262021-08-27 18:48:22 -040020- Alpine >= 3.12
21- Debian >= 10
Davide Pesavento2349e282020-03-24 14:28:03 -040022- Fedora >= 29
Ivan Yeoba1a4a92015-01-11 00:45:57 -080023- Gentoo Linux
Davide Pesavento3ffae262021-08-27 18:48:22 -040024- Raspberry Pi OS (formerly Raspbian) >= 2019-06-20
Davide Pesaventod776a932020-03-20 18:42:36 -040025- FreeBSD >= 11.3
Davide Pesavento3ffae262021-08-27 18:48:22 -040026- macOS 10.13
27- macOS 10.14
Davide Pesavento534b8412018-12-08 19:19:09 -050028
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070029Prerequisites
30-------------
31
Davide Pesaventoab7300b2020-04-09 00:51:41 -040032Required
33~~~~~~~~
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070034
Davide Pesavento71c622b2020-04-24 01:39:01 -040035- GCC >= 7.4 or clang >= 4.0 (on Linux and FreeBSD)
36- Xcode >= 9.0 (on macOS)
Davide Pesavento78338c52020-04-20 23:00:02 -040037- Python >= 3.6
Davide Pesaventoab7300b2020-04-09 00:51:41 -040038- pkg-config
Davide Pesavento78338c52020-04-20 23:00:02 -040039- Boost >= 1.65.1
Davide Pesavento534b8412018-12-08 19:19:09 -050040- OpenSSL >= 1.0.2
Davide Pesaventod776a932020-03-20 18:42:36 -040041- SQLite 3.x
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070042
Davide Pesaventoab7300b2020-04-09 00:51:41 -040043To build ndn-cxx from source, one must first install a C++ compiler and all necessary
44development tools and libraries:
Davide Pesaventod776a932020-03-20 18:42:36 -040045
Davide Pesavento933a5672020-07-03 22:32:43 -040046- On **Ubuntu**
Davide Pesaventod776a932020-03-20 18:42:36 -040047
48 In a terminal, enter::
49
Davide Pesavento30ed6282021-07-25 20:05:06 -040050 sudo apt install build-essential pkg-config python3-minimal libboost-all-dev libssl-dev libsqlite3-dev
Davide Pesaventod776a932020-03-20 18:42:36 -040051
Davide Pesavento933a5672020-07-03 22:32:43 -040052- On **CentOS** and **Fedora**
Davide Pesaventod776a932020-03-20 18:42:36 -040053
54 In a terminal, enter::
55
Davide Pesavento2349e282020-03-24 14:28:03 -040056 sudo dnf install gcc-c++ pkgconf-pkg-config python3 boost-devel openssl-devel sqlite-devel
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070057
Davide Pesavento933a5672020-07-03 22:32:43 -040058- On **macOS**
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070059
Davide Pesaventod776a932020-03-20 18:42:36 -040060 * Install either Xcode (from the App Store) or the Command Line Tools
61 (with ``xcode-select --install``)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070062
Davide Pesaventocad94b02021-04-09 21:23:03 -040063 * If using Homebrew (recommended), enter the following in a terminal:
64
65 .. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070066
Davide Pesavento534b8412018-12-08 19:19:09 -050067 brew install boost openssl pkg-config
Davide Pesaventocad94b02021-04-09 21:23:03 -040068 brew install python # only on macOS 10.14 and earlier
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070069
Davide Pesavento933a5672020-07-03 22:32:43 -040070 .. warning::
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070071
Davide Pesavento534b8412018-12-08 19:19:09 -050072 If a major OS upgrade is performed after installing the dependencies
73 with Homebrew, remember to reinstall all packages.
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070074
Davide Pesavento933a5672020-07-03 22:32:43 -040075- On **FreeBSD**
Davide Pesavento534b8412018-12-08 19:19:09 -050076
77 In a terminal, enter::
78
Davide Pesaventod776a932020-03-20 18:42:36 -040079 sudo pkg install pkgconf python3 boost-libs openssl sqlite3
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070080
Davide Pesaventoab7300b2020-04-09 00:51:41 -040081Optional
82~~~~~~~~
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070083
Davide Pesavento01cea502021-07-31 19:25:42 -040084To build tutorials, man pages, and API documentation the following additional dependencies
Davide Pesaventoab7300b2020-04-09 00:51:41 -040085need to be installed:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070086
Davide Pesaventoab7300b2020-04-09 00:51:41 -040087- doxygen
88- graphviz
Davide Pesavento933a5672020-07-03 22:32:43 -040089- sphinx >= 1.3
Davide Pesaventoab7300b2020-04-09 00:51:41 -040090- sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070091
Davide Pesaventod776a932020-03-20 18:42:36 -040092The following lists the steps to install these prerequisites on various common platforms.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070093
Davide Pesavento3ffae262021-08-27 18:48:22 -040094.. note::
95 On Linux, you may need to add ``$HOME/.local/bin`` to the ``PATH`` environment variable
96 for your user, for example:
97
98 .. code-block:: sh
99
100 export PATH="${HOME}/.local/bin${PATH:+:}${PATH}"
101
Davide Pesavento933a5672020-07-03 22:32:43 -0400102- On **Ubuntu**:
103
104 .. code-block:: sh
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700105
Davide Pesavento534b8412018-12-08 19:19:09 -0500106 sudo apt install doxygen graphviz python3-pip
Davide Pesavento30ed6282021-07-25 20:05:06 -0400107 pip3 install --user sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700108
Davide Pesavento933a5672020-07-03 22:32:43 -0400109- On **CentOS** and **Fedora**:
110
111 .. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700112
Davide Pesaventocad94b02021-04-09 21:23:03 -0400113 sudo dnf config-manager --enable powertools # on CentOS only
Davide Pesavento2349e282020-03-24 14:28:03 -0400114 sudo dnf install doxygen graphviz python3-pip
115 pip3 install --user sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700116
Davide Pesavento933a5672020-07-03 22:32:43 -0400117- On **macOS**:
118
119 .. code-block:: sh
Davide Pesaventod776a932020-03-20 18:42:36 -0400120
121 brew install doxygen graphviz
Davide Pesavento30ed6282021-07-25 20:05:06 -0400122 sudo pip3 install sphinx sphinxcontrib-doxylink
Davide Pesaventod776a932020-03-20 18:42:36 -0400123
Davide Pesavento933a5672020-07-03 22:32:43 -0400124- On **FreeBSD**:
125
126 .. code-block:: sh
Davide Pesavento534b8412018-12-08 19:19:09 -0500127
Davide Pesaventod776a932020-03-20 18:42:36 -0400128 sudo pkg install doxygen graphviz py37-sphinx
Davide Pesavento534b8412018-12-08 19:19:09 -0500129
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700130Build
131-----
132
Davide Pesavento534b8412018-12-08 19:19:09 -0500133.. note::
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400134 These are instructions for regular builds of ndn-cxx (release mode). If you are
135 planning to develop the ndn-cxx code itself, you should do a :ref:`Development build`.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700136
Davide Pesavento933a5672020-07-03 22:32:43 -0400137To build in a terminal, change directory to the ndn-cxx root, then enter:
138
139.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700140
Davide Pesavento2349e282020-03-24 14:28:03 -0400141 ./waf configure # on CentOS, add --without-pch
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700142 ./waf
143 sudo ./waf install
144
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400145By default, only the shared variant of the ndn-cxx library will be built. To build the
Davide Pesavento933a5672020-07-03 22:32:43 -0400146static library, pass ``--enable-static`` to the ``./waf configure`` command:
147
148.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700149
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700150 ./waf configure --enable-static
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700151
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400152To disable the build of the shared library and build only the static library, use the
153additional ``--disable-shared`` option. Note that at least one variant of the library
154needs to be enabled.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700155
Davide Pesavento933a5672020-07-03 22:32:43 -0400156.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700157
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700158 ./waf configure --enable-static --disable-shared
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700159
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400160On Linux, it is necessary to run the following command after the shared library has
Davide Pesavento933a5672020-07-03 22:32:43 -0400161been installed:
162
163.. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700164
Davide Pesavento534b8412018-12-08 19:19:09 -0500165 sudo ldconfig
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700166
Davide Pesavento534b8412018-12-08 19:19:09 -0500167.. note::
168 When the library is installed in a non-standard path (in general: not in ``/usr/lib``
169 or ``/usr/local/lib``; on some Linux distros including Fedora: not in ``/usr/lib``),
170 additional actions may be necessary.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700171
Davide Pesavento534b8412018-12-08 19:19:09 -0500172 The installation path should be added to ``/etc/ld.so.conf`` (or in
Davide Pesavento933a5672020-07-03 22:32:43 -0400173 ``/etc/ld.so.conf.d``) **before** running ``sudo ldconfig``. For example:
174
175 .. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700176
Davide Pesavento534b8412018-12-08 19:19:09 -0500177 echo /usr/local/lib | sudo tee /etc/ld.so.conf.d/ndn-cxx.conf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700178
Davide Pesavento534b8412018-12-08 19:19:09 -0500179 Alternatively, the ``LD_LIBRARY_PATH`` environment variable can be set to point to
Davide Pesavento933a5672020-07-03 22:32:43 -0400180 the installation directory of the shared library:
181
182 .. code-block:: sh
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700183
Davide Pesavento534b8412018-12-08 19:19:09 -0500184 export LD_LIBRARY_PATH=/usr/local/lib
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700185
Davide Pesavento534b8412018-12-08 19:19:09 -0500186The ``./waf install`` command installs the following files:
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700187
Davide Pesavento534b8412018-12-08 19:19:09 -0500188- ``<LIBPATH>/libndn-cxx.a``: static NDN C++ library (if enabled).
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700189- ``<LIBPATH>/libndn-cxx.so``, ``<LIBPATH>/libndn-cxx.so.<VERSION>`` (on Linux),
Davide Pesavento534b8412018-12-08 19:19:09 -0500190 ``<LIBPATH>/libndn-cxx.dylib``, ``<LIBPATH>/libndn-cxx.<VERSION>.dylib`` (on macOS):
191 shared NDN C++ library (if enabled).
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400192- ``<LIBPATH>/pkgconfig/libndn-cxx.pc``: pkgconfig file storing all necessary flags to
193 build against the library. For example, if the ``pkg-config`` or ``pkgconf-pkg-config``
194 package is installed and ``PKG_CONFIG_PATH`` is configured properly (or if
195 ``<LIBPATH>/pkgconfig`` is a default search path), the command ``pkg-config --cflags
196 --libs libndn-cxx`` will return all necessary compile and link flags for the library.
Davide Pesavento534b8412018-12-08 19:19:09 -0500197- ``<BINPATH>/ndnsec``: tool to manage NDN keys and certificates.
198- ``<BINPATH>/ndnsec-*``: convenience aliases for ``ndnsec`` tools.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700199
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400200If configured with tests (``./waf configure --with-tests``), the above commands
201will also produce:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700202
Davide Pesavento534b8412018-12-08 19:19:09 -0500203- ``build/unit-tests``: a unit test binary for the library.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700204
Davide Pesaventoab7300b2020-04-09 00:51:41 -04002051.5 GB available memory per CPU core is necessary for efficient compilation. On a
206multi-core machine with less than 1.5 GB available memory per CPU core, limit the
207objects being compiled in parallel with ``./waf -jN``, where N is the amount of
208available memory divided by 1.5 GB (e.g., ``./waf -j2`` for 3 GB of memory). This
209should avoid memory thrashing and result in faster compilation.
Junxiao Shie04bd832014-11-29 23:02:38 -0700210
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700211Build with examples
212-------------------
213
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400214By default, the examples in the ``examples/`` directory will not be built. To enable
Davide Pesavento933a5672020-07-03 22:32:43 -0400215them, pass ``--with-examples`` during the configuration step:
216
217.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700218
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400219 ./waf configure --with-examples # on CentOS, add --without-pch
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700220 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700221 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400222 sudo ldconfig # on Linux only
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700223
Davide Pesavento933a5672020-07-03 22:32:43 -0400224To run the examples:
225
226.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700227
228 # trivial producer app
229 ./build/examples/producer
230
231 # trivial consumer app
232 ./build/examples/consumer
233
234 # trivial consumer app with timers
235 ./build/examples/consumer-with-timer
236
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400237If you want to make a new sample application, just create a ``.cpp`` file inside the
Davide Pesavento933a5672020-07-03 22:32:43 -0400238``examples/`` directory and it will be compiled during the next run of ``./waf``:
239
240.. code-block:: sh
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700241
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400242 cp examples/consumer.cpp examples/my-new-app.cpp
243 ... # edit examples/my-new-app.cpp with your preferred editor
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700244 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700245 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400246 sudo ldconfig # on Linux only
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400247 ./build/examples/my-new-app
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700248
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700249Debug symbols
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400250-------------
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700251
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400252The default compiler flags include debug symbols in binaries. This should provide
253more meaningful debugging information if ndn-cxx or your application crashes.
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700254
Eric Newberrybdfb53a2020-10-01 10:43:46 -0700255If this is not desired, the default flags can be overridden to disable debug symbols.
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400256The following example shows how to completely disable debug symbols and configure
257ndn-cxx to be installed into ``/usr`` with configuration in the ``/etc`` directory.
258
Davide Pesavento933a5672020-07-03 22:32:43 -0400259.. code-block:: sh
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700260
261 CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc
262 ./waf
263 sudo ./waf install
264
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400265Customizing the compiler
266------------------------
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700267
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400268To build ndn-cxx with a different compiler (rather than the platform default), set the
269``CXX`` environment variable to point to the compiler binary. For example, to build
Davide Pesavento933a5672020-07-03 22:32:43 -0400270with clang on Linux, use the following:
271
272.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700273
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400274 CXX=clang++ ./waf configure
275
276Building the documentation
277--------------------------
278
Eric Newberrybdfb53a2020-10-01 10:43:46 -0700279Tutorials and API documentation can be built using the following commands:
Davide Pesavento933a5672020-07-03 22:32:43 -0400280
281.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700282
283 # Full set of documentation (tutorials + API) in build/docs
284 ./waf docs
285
Davide Pesavento2349e282020-03-24 14:28:03 -0400286 # Only tutorials in build/docs
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700287 ./waf sphinx
288
Davide Pesavento2349e282020-03-24 14:28:03 -0400289 # Only API docs in build/docs/doxygen
Sepehr Abdous4fc6db22018-08-22 15:26:06 -0700290 ./waf doxygen
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700291
Davide Pesavento01cea502021-07-31 19:25:42 -0400292If ``sphinx-build`` is detected during ``./waf configure``, man pages will automatically
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400293be built and installed during the normal build process (i.e., during ``./waf`` and
Davide Pesavento01cea502021-07-31 19:25:42 -0400294``./waf install``). By default, man pages will be installed into ``${PREFIX}/share/man``
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400295(the default value for ``PREFIX`` is ``/usr/local``). This location can be changed
296during the ``./waf configure`` stage using the ``--prefix``, ``--datarootdir``, or
297``--mandir`` options.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700298
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400299For further details, please refer to ``./waf --help``.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700300
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400301.. _Development build:
Davide Pesavento534b8412018-12-08 19:19:09 -0500302
303Development build
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700304-----------------
305
Davide Pesavento933a5672020-07-03 22:32:43 -0400306The following is the suggested build procedure for development builds:
307
308.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700309
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400310 ./waf configure --debug --with-tests # on CentOS, add --without-pch
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700311 ./waf
312 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400313 sudo ldconfig # on Linux only
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700314
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400315In a development build, most compiler optimizations will be disabled and all warnings
316will be treated as errors. This default behavior can be overridden by setting the
Davide Pesavento933a5672020-07-03 22:32:43 -0400317``CXXFLAGS`` environment variable before running ``./waf configure``, for example:
318
319.. code-block:: sh
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700320
321 CXXFLAGS="-O1 -g3" ./waf configure --debug --with-tests
322 ...