blob: 9de5b9012896cbd0308fdef7b77c767d74128c66 [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)
Alexander Afanasyevcf8ffd42019-12-29 17:58:53 -080011- Ubuntu 19.10 (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 Pesaventoab7300b2020-04-09 00:51:41 -040032- GCC >= 5.3 or clang >= 3.6
Davide Pesavento78338c52020-04-20 23:00:02 -040033- Python >= 3.6
Davide Pesaventoab7300b2020-04-09 00:51:41 -040034- pkg-config
Davide Pesavento78338c52020-04-20 23:00:02 -040035- Boost >= 1.65.1
Davide Pesavento534b8412018-12-08 19:19:09 -050036- OpenSSL >= 1.0.2
Davide Pesaventod776a932020-03-20 18:42:36 -040037- SQLite 3.x
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070038
Davide Pesaventoab7300b2020-04-09 00:51:41 -040039To build ndn-cxx from source, one must first install a C++ compiler and all necessary
40development tools and libraries:
Davide Pesaventod776a932020-03-20 18:42:36 -040041
42- Ubuntu
43
44 In a terminal, enter::
45
Davide Pesavento2349e282020-03-24 14:28:03 -040046 sudo apt install g++ pkg-config python3-minimal libboost-all-dev libssl-dev libsqlite3-dev
Davide Pesaventod776a932020-03-20 18:42:36 -040047
Davide Pesavento2349e282020-03-24 14:28:03 -040048- CentOS and Fedora
Davide Pesaventod776a932020-03-20 18:42:36 -040049
50 In a terminal, enter::
51
Davide Pesavento2349e282020-03-24 14:28:03 -040052 sudo dnf install gcc-c++ pkgconf-pkg-config python3 boost-devel openssl-devel sqlite-devel
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070053
Davide Pesavento534b8412018-12-08 19:19:09 -050054- macOS
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070055
Davide Pesaventod776a932020-03-20 18:42:36 -040056 * Install either Xcode (from the App Store) or the Command Line Tools
57 (with ``xcode-select --install``)
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070058
Davide Pesavento534b8412018-12-08 19:19:09 -050059 * If using Homebrew (recommended), enter the following in a terminal::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070060
Davide Pesavento534b8412018-12-08 19:19:09 -050061 brew install boost openssl pkg-config
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070062
Davide Pesavento534b8412018-12-08 19:19:09 -050063 .. note::
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070064
Davide Pesavento534b8412018-12-08 19:19:09 -050065 If a major OS upgrade is performed after installing the dependencies
66 with Homebrew, remember to reinstall all packages.
Alexander Afanasyev67cb75c2016-06-15 12:34:58 -070067
Davide Pesavento534b8412018-12-08 19:19:09 -050068- FreeBSD
69
70 In a terminal, enter::
71
Davide Pesaventod776a932020-03-20 18:42:36 -040072 sudo pkg install pkgconf python3 boost-libs openssl sqlite3
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070073
Davide Pesaventoab7300b2020-04-09 00:51:41 -040074Optional
75~~~~~~~~
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070076
Davide Pesaventoab7300b2020-04-09 00:51:41 -040077To build tutorials, manpages, and API documentation the following additional dependencies
78need to be installed:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070079
Davide Pesaventoab7300b2020-04-09 00:51:41 -040080- doxygen
81- graphviz
82- sphinx
83- sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070084
Davide Pesaventod776a932020-03-20 18:42:36 -040085The following lists the steps to install these prerequisites on various common platforms.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070086
Davide Pesavento534b8412018-12-08 19:19:09 -050087- On Ubuntu::
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -070088
Davide Pesavento534b8412018-12-08 19:19:09 -050089 sudo apt install doxygen graphviz python3-pip
90 sudo pip3 install sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070091
Davide Pesavento2349e282020-03-24 14:28:03 -040092- On CentOS and Fedora::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070093
Davide Pesavento2349e282020-03-24 14:28:03 -040094 sudo dnf config-manager --enable PowerTools # on CentOS only
95 sudo dnf install doxygen graphviz python3-pip
96 pip3 install --user sphinx sphinxcontrib-doxylink
Alexander Afanasyevc5452c52014-04-29 17:21:51 -070097
Davide Pesaventod776a932020-03-20 18:42:36 -040098- On macOS::
99
100 brew install doxygen graphviz
101 sudo pip install sphinx sphinxcontrib-doxylink
102
Davide Pesavento534b8412018-12-08 19:19:09 -0500103- On FreeBSD::
104
Davide Pesaventod776a932020-03-20 18:42:36 -0400105 sudo pkg install doxygen graphviz py37-sphinx
Davide Pesavento534b8412018-12-08 19:19:09 -0500106
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700107Build
108-----
109
Davide Pesavento534b8412018-12-08 19:19:09 -0500110.. note::
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400111 These are instructions for regular builds of ndn-cxx (release mode). If you are
112 planning to develop the ndn-cxx code itself, you should do a :ref:`Development build`.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700113
Davide Pesavento534b8412018-12-08 19:19:09 -0500114To build in a terminal, change directory to the ndn-cxx root, then enter::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700115
Davide Pesavento2349e282020-03-24 14:28:03 -0400116 ./waf configure # on CentOS, add --without-pch
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700117 ./waf
118 sudo ./waf install
119
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400120By default, only the shared variant of the ndn-cxx library will be built. To build the
121static library, pass ``--enable-static`` to the ``./waf configure`` command::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700122
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700123 ./waf configure --enable-static
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700124
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400125To disable the build of the shared library and build only the static library, use the
126additional ``--disable-shared`` option. Note that at least one variant of the library
127needs to be enabled.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700128
129::
130
Spyridon Mastorakis5ebfda62015-07-21 20:57:40 -0700131 ./waf configure --enable-static --disable-shared
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700132
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400133On Linux, it is necessary to run the following command after the shared library has
134been installed::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700135
Davide Pesavento534b8412018-12-08 19:19:09 -0500136 sudo ldconfig
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700137
Davide Pesavento534b8412018-12-08 19:19:09 -0500138.. note::
139 When the library is installed in a non-standard path (in general: not in ``/usr/lib``
140 or ``/usr/local/lib``; on some Linux distros including Fedora: not in ``/usr/lib``),
141 additional actions may be necessary.
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700142
Davide Pesavento534b8412018-12-08 19:19:09 -0500143 The installation path should be added to ``/etc/ld.so.conf`` (or in
144 ``/etc/ld.so.conf.d``) **before** running ``sudo ldconfig``. For example::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700145
Davide Pesavento534b8412018-12-08 19:19:09 -0500146 echo /usr/local/lib | sudo tee /etc/ld.so.conf.d/ndn-cxx.conf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700147
Davide Pesavento534b8412018-12-08 19:19:09 -0500148 Alternatively, the ``LD_LIBRARY_PATH`` environment variable can be set to point to
149 the installation directory of the shared library::
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700150
Davide Pesavento534b8412018-12-08 19:19:09 -0500151 export LD_LIBRARY_PATH=/usr/local/lib
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700152
Davide Pesavento534b8412018-12-08 19:19:09 -0500153The ``./waf install`` command installs the following files:
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700154
Davide Pesavento534b8412018-12-08 19:19:09 -0500155- ``<LIBPATH>/libndn-cxx.a``: static NDN C++ library (if enabled).
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700156- ``<LIBPATH>/libndn-cxx.so``, ``<LIBPATH>/libndn-cxx.so.<VERSION>`` (on Linux),
Davide Pesavento534b8412018-12-08 19:19:09 -0500157 ``<LIBPATH>/libndn-cxx.dylib``, ``<LIBPATH>/libndn-cxx.<VERSION>.dylib`` (on macOS):
158 shared NDN C++ library (if enabled).
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400159- ``<LIBPATH>/pkgconfig/libndn-cxx.pc``: pkgconfig file storing all necessary flags to
160 build against the library. For example, if the ``pkg-config`` or ``pkgconf-pkg-config``
161 package is installed and ``PKG_CONFIG_PATH`` is configured properly (or if
162 ``<LIBPATH>/pkgconfig`` is a default search path), the command ``pkg-config --cflags
163 --libs libndn-cxx`` will return all necessary compile and link flags for the library.
Davide Pesavento534b8412018-12-08 19:19:09 -0500164- ``<BINPATH>/ndnsec``: tool to manage NDN keys and certificates.
165- ``<BINPATH>/ndnsec-*``: convenience aliases for ``ndnsec`` tools.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700166
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400167If configured with tests (``./waf configure --with-tests``), the above commands
168will also produce:
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700169
Davide Pesavento534b8412018-12-08 19:19:09 -0500170- ``build/unit-tests``: a unit test binary for the library.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700171
Davide Pesaventoab7300b2020-04-09 00:51:41 -04001721.5 GB available memory per CPU core is necessary for efficient compilation. On a
173multi-core machine with less than 1.5 GB available memory per CPU core, limit the
174objects being compiled in parallel with ``./waf -jN``, where N is the amount of
175available memory divided by 1.5 GB (e.g., ``./waf -j2`` for 3 GB of memory). This
176should avoid memory thrashing and result in faster compilation.
Junxiao Shie04bd832014-11-29 23:02:38 -0700177
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700178Build with examples
179-------------------
180
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400181By default, the examples in the ``examples/`` directory will not be built. To enable
182them, pass ``--with-examples`` during the configuration step::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700183
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400184 ./waf configure --with-examples # on CentOS, add --without-pch
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700185 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700186 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400187 sudo ldconfig # on Linux only
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700188
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400189To run the examples::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700190
191 # trivial producer app
192 ./build/examples/producer
193
194 # trivial consumer app
195 ./build/examples/consumer
196
197 # trivial consumer app with timers
198 ./build/examples/consumer-with-timer
199
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400200If you want to make a new sample application, just create a ``.cpp`` file inside the
201``examples/`` directory and it will be compiled during the next run of ``./waf``::
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700202
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400203 cp examples/consumer.cpp examples/my-new-app.cpp
204 ... # edit examples/my-new-app.cpp with your preferred editor
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700205 ./waf
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700206 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400207 sudo ldconfig # on Linux only
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400208 ./build/examples/my-new-app
Alexander Afanasyevc8bcd452014-05-12 17:58:47 -0700209
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700210Debug symbols
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400211-------------
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700212
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400213The default compiler flags include debug symbols in binaries. This should provide
214more meaningful debugging information if ndn-cxx or your application crashes.
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700215
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400216If this is undesirable, the default flags can be overridden to disable debug symbols.
217The following example shows how to completely disable debug symbols and configure
218ndn-cxx to be installed into ``/usr`` with configuration in the ``/etc`` directory.
219
220::
Alexander Afanasyev9b0e1142014-05-08 00:17:34 -0700221
222 CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc
223 ./waf
224 sudo ./waf install
225
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400226Customizing the compiler
227------------------------
Alexander Afanasyev7ed29432015-06-05 18:01:16 -0700228
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400229To build ndn-cxx with a different compiler (rather than the platform default), set the
230``CXX`` environment variable to point to the compiler binary. For example, to build
231with clang on Linux, use the following::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700232
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400233 CXX=clang++ ./waf configure
234
235Building the documentation
236--------------------------
237
238ndn-cxx tutorials and API documentation can be built using the following commands::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700239
240 # Full set of documentation (tutorials + API) in build/docs
241 ./waf docs
242
Davide Pesavento2349e282020-03-24 14:28:03 -0400243 # Only tutorials in build/docs
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700244 ./waf sphinx
245
Davide Pesavento2349e282020-03-24 14:28:03 -0400246 # Only API docs in build/docs/doxygen
Sepehr Abdous4fc6db22018-08-22 15:26:06 -0700247 ./waf doxygen
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700248
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400249If ``sphinx-build`` is detected during ``./waf configure``, manpages will automatically
250be built and installed during the normal build process (i.e., during ``./waf`` and
251``./waf install``). By default, manpages will be installed into ``${PREFIX}/share/man``
252(the default value for ``PREFIX`` is ``/usr/local``). This location can be changed
253during the ``./waf configure`` stage using the ``--prefix``, ``--datarootdir``, or
254``--mandir`` options.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700255
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400256For further details, please refer to ``./waf --help``.
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700257
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400258.. _Development build:
Davide Pesavento534b8412018-12-08 19:19:09 -0500259
260Development build
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700261-----------------
262
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400263The following is the suggested build procedure for development builds::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700264
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400265 ./waf configure --debug --with-tests # on CentOS, add --without-pch
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700266 ./waf
267 sudo ./waf install
Davide Pesavento2349e282020-03-24 14:28:03 -0400268 sudo ldconfig # on Linux only
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700269
Davide Pesaventoab7300b2020-04-09 00:51:41 -0400270In a development build, most compiler optimizations will be disabled and all warnings
271will be treated as errors. This default behavior can be overridden by setting the
272``CXXFLAGS`` environment variable before running ``./waf configure``, for example::
Alexander Afanasyevc5452c52014-04-29 17:21:51 -0700273
274 CXXFLAGS="-O1 -g3" ./waf configure --debug --with-tests
275 ...