Alexander Afanasyev | abaab52 | 2014-04-30 20:42:11 -0700 | [diff] [blame] | 1 | .. _Getting Started with ndn-cxx: |
| 2 | |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 3 | Getting started with ndn-cxx |
| 4 | ============================ |
| 5 | |
| 6 | Supported platforms |
| 7 | ------------------- |
| 8 | |
| 9 | ndn-cxx uses continuous integration and has been tested on the following |
| 10 | platforms: |
| 11 | |
Davide Pesavento | 7c4ad51 | 2018-04-28 15:20:11 -0400 | [diff] [blame^] | 12 | - Ubuntu 14.04 (amd64) |
| 13 | - Ubuntu 16.04 (amd64, armhf, i386) |
| 14 | - Ubuntu 18.04 (amd64) |
Davide Pesavento | e11c8d8 | 2016-04-16 14:32:07 +0200 | [diff] [blame] | 15 | - OS X 10.11 |
Davide Pesavento | 0530b5b | 2016-11-07 03:23:58 +0100 | [diff] [blame] | 16 | - macOS 10.12 |
Eric Newberry | 935d7fe | 2017-10-29 15:09:36 -0700 | [diff] [blame] | 17 | - macOS 10.13 |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 18 | |
| 19 | ndn-cxx is known to work on the following platforms, although they are not officially |
| 20 | supported: |
| 21 | |
Davide Pesavento | 7c4ad51 | 2018-04-28 15:20:11 -0400 | [diff] [blame^] | 22 | - Debian >= 9 |
| 23 | - Fedora >= 24 |
Ivan Yeo | ba1a4a9 | 2015-01-11 00:45:57 -0800 | [diff] [blame] | 24 | - Gentoo Linux |
Davide Pesavento | 7c4ad51 | 2018-04-28 15:20:11 -0400 | [diff] [blame^] | 25 | - Raspbian >= 2017-08-16 |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 26 | |
| 27 | Prerequisites |
| 28 | ------------- |
| 29 | |
| 30 | Required: |
| 31 | ~~~~~~~~~ |
| 32 | |
Davide Pesavento | 7c4ad51 | 2018-04-28 15:20:11 -0400 | [diff] [blame^] | 33 | - ``python2`` >= 2.7, or ``python3`` >= 3.4 |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 34 | - ``libsqlite3`` |
Davide Pesavento | 0530b5b | 2016-11-07 03:23:58 +0100 | [diff] [blame] | 35 | - OpenSSL >= 1.0.1 |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 36 | - ``pkg-config`` |
Davide Pesavento | e6e6fde | 2016-04-16 14:44:45 +0200 | [diff] [blame] | 37 | - Boost libraries >= 1.54 |
Davide Pesavento | 0530b5b | 2016-11-07 03:23:58 +0100 | [diff] [blame] | 38 | - OSX Security framework (on OSX/macOS platform only) |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 39 | |
| 40 | Following are the detailed steps for each platform to install the compiler, all necessary |
| 41 | development tools and libraries, and ndn-cxx prerequisites. |
| 42 | |
Davide Pesavento | 0530b5b | 2016-11-07 03:23:58 +0100 | [diff] [blame] | 43 | - OS X / macOS |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | 67cb75c | 2016-06-15 12:34:58 -0700 | [diff] [blame] | 45 | Install Xcode from AppStore or at least Command Line Tools (``xcode-select --install``) |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 46 | |
Alexander Afanasyev | 67cb75c | 2016-06-15 12:34:58 -0700 | [diff] [blame] | 47 | * When using MacPorts |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 48 | |
Alexander Afanasyev | 67cb75c | 2016-06-15 12:34:58 -0700 | [diff] [blame] | 49 | In a terminal, enter:: |
| 50 | |
Davide Pesavento | 006b7ce | 2017-08-16 00:55:02 -0400 | [diff] [blame] | 51 | sudo port install pkgconfig boost sqlite3 openssl |
Alexander Afanasyev | 67cb75c | 2016-06-15 12:34:58 -0700 | [diff] [blame] | 52 | |
| 53 | * When using Homebrew |
| 54 | |
| 55 | In a terminal, enter:: |
| 56 | |
Davide Pesavento | 006b7ce | 2017-08-16 00:55:02 -0400 | [diff] [blame] | 57 | brew install boost openssl pkg-config |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 58 | |
Junxiao Shi | 190bee2 | 2015-02-14 19:21:36 -0700 | [diff] [blame] | 59 | .. note:: |
| 60 | |
Davide Pesavento | 0530b5b | 2016-11-07 03:23:58 +0100 | [diff] [blame] | 61 | If a major OS upgrade is performed after installing dependencies with |
Alexander Afanasyev | 67cb75c | 2016-06-15 12:34:58 -0700 | [diff] [blame] | 62 | MacPorts or Homebrew, remember to reinstall all packages. |
Junxiao Shi | 190bee2 | 2015-02-14 19:21:36 -0700 | [diff] [blame] | 63 | |
Ivan Yeo | ba1a4a9 | 2015-01-11 00:45:57 -0800 | [diff] [blame] | 64 | - Ubuntu |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 65 | |
Alexander Afanasyev | 67cb75c | 2016-06-15 12:34:58 -0700 | [diff] [blame] | 66 | In a terminal, enter:: |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 67 | |
Davide Pesavento | 006b7ce | 2017-08-16 00:55:02 -0400 | [diff] [blame] | 68 | sudo apt-get install build-essential libsqlite3-dev libboost-all-dev libssl-dev |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 69 | |
Ivan Yeo | ba1a4a9 | 2015-01-11 00:45:57 -0800 | [diff] [blame] | 70 | - Fedora |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 71 | |
Alexander Afanasyev | 67cb75c | 2016-06-15 12:34:58 -0700 | [diff] [blame] | 72 | In a terminal, enter:: |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 73 | |
Alexander Afanasyev | 67cb75c | 2016-06-15 12:34:58 -0700 | [diff] [blame] | 74 | sudo yum install gcc-g++ git |
Davide Pesavento | 006b7ce | 2017-08-16 00:55:02 -0400 | [diff] [blame] | 75 | sudo yum install sqlite-devel boost-devel openssl-devel |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 76 | |
| 77 | Optional: |
| 78 | ~~~~~~~~~ |
| 79 | |
| 80 | To build tutorials, manpages, and API documentation the following |
| 81 | dependencies need to be installed: |
| 82 | |
| 83 | - ``doxygen`` |
| 84 | - ``graphviz`` |
Alexander Afanasyev | 9b0e114 | 2014-05-08 00:17:34 -0700 | [diff] [blame] | 85 | - ``python-sphinx`` and sphinx extensions ``sphinxcontrib-doxylink``, |
| 86 | ``sphinxcontrib-googleanalytics`` |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | 9b0e114 | 2014-05-08 00:17:34 -0700 | [diff] [blame] | 88 | The following lists steps for common platforms to install these prerequisites: |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 89 | |
Davide Pesavento | 0530b5b | 2016-11-07 03:23:58 +0100 | [diff] [blame] | 90 | - On OS X / macOS with MacPorts:: |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 91 | |
| 92 | sudo port install doxygen graphviz py27-sphinx sphinx_select |
| 93 | sudo port select sphinx py27-sphinx |
| 94 | |
Alexander Afanasyev | 9b0e114 | 2014-05-08 00:17:34 -0700 | [diff] [blame] | 95 | # Install sphinx extensions |
| 96 | sudo port install py27-pip |
| 97 | sudo port select pip pip27 |
| 98 | sudo pip install sphinxcontrib-doxylink sphinxcontrib-googleanalytics |
| 99 | |
Ivan Yeo | ba1a4a9 | 2015-01-11 00:45:57 -0800 | [diff] [blame] | 100 | - On Ubuntu:: |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 101 | |
Alexander Afanasyev | 9b0e114 | 2014-05-08 00:17:34 -0700 | [diff] [blame] | 102 | sudo apt-get install doxygen graphviz python-sphinx python-pip |
| 103 | sudo pip install sphinxcontrib-doxylink sphinxcontrib-googleanalytics |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 104 | |
Ivan Yeo | ba1a4a9 | 2015-01-11 00:45:57 -0800 | [diff] [blame] | 105 | - On Fedora:: |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 106 | |
Alexander Afanasyev | 5946ed1 | 2015-01-19 23:41:39 -0800 | [diff] [blame] | 107 | sudo yum install doxygen graphviz python-sphinx |
Alexander Afanasyev | 9b0e114 | 2014-05-08 00:17:34 -0700 | [diff] [blame] | 108 | sudo pip install sphinxcontrib-doxylink sphinxcontrib-googleanalytics |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 109 | |
Alexander Afanasyev | 7ed2943 | 2015-06-05 18:01:16 -0700 | [diff] [blame] | 110 | .. _build: |
| 111 | |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 112 | Build |
| 113 | ----- |
| 114 | |
| 115 | (These are instructions to build ndn-cxx. To do development of ndn-cxx |
| 116 | code and update the build system, see Development.) |
| 117 | |
| 118 | To build in a terminal, change directory to the ndn-cxx root. Enter: |
| 119 | |
| 120 | :: |
| 121 | |
| 122 | ./waf configure |
| 123 | ./waf |
| 124 | sudo ./waf install |
| 125 | |
Spyridon Mastorakis | 5ebfda6 | 2015-07-21 20:57:40 -0700 | [diff] [blame] | 126 | By default, only the shared version of ndn-cxx library is built. To build the static library, |
| 127 | use ``--enable-static`` option for ``./waf configure`` command. For example:: |
Alexander Afanasyev | 7ed2943 | 2015-06-05 18:01:16 -0700 | [diff] [blame] | 128 | |
Spyridon Mastorakis | 5ebfda6 | 2015-07-21 20:57:40 -0700 | [diff] [blame] | 129 | ./waf configure --enable-static |
Alexander Afanasyev | 7ed2943 | 2015-06-05 18:01:16 -0700 | [diff] [blame] | 130 | |
Spyridon Mastorakis | 5ebfda6 | 2015-07-21 20:57:40 -0700 | [diff] [blame] | 131 | To disable build of the shared library and build only the static library, use additional |
| 132 | ``--disable-shared`` option. Note that at least one version of the library needs to be |
Alexander Afanasyev | 7ed2943 | 2015-06-05 18:01:16 -0700 | [diff] [blame] | 133 | enabled. |
| 134 | |
| 135 | :: |
| 136 | |
Spyridon Mastorakis | 5ebfda6 | 2015-07-21 20:57:40 -0700 | [diff] [blame] | 137 | ./waf configure --enable-static --disable-shared |
Alexander Afanasyev | 7ed2943 | 2015-06-05 18:01:16 -0700 | [diff] [blame] | 138 | |
| 139 | |
Spyridon Mastorakis | 5ebfda6 | 2015-07-21 20:57:40 -0700 | [diff] [blame] | 140 | After the shared library is built and installed, some systems require additional actions. |
Alexander Afanasyev | 7ed2943 | 2015-06-05 18:01:16 -0700 | [diff] [blame] | 141 | |
| 142 | - on Linux:: |
| 143 | |
| 144 | sudo ldconfig |
| 145 | |
| 146 | - on FreeBSD:: |
| 147 | |
| 148 | sudo ldconfig -m |
| 149 | |
| 150 | .. note:: |
| 151 | When library is installed in a non-standard path (in general: not in ``/usr/lib`` or |
| 152 | ``/usr/local/lib``; on some Linux distros including Fedora: not in ``/usr/lib``), |
| 153 | additional actions may be necessary. |
| 154 | |
| 155 | The installation path should be added to ``/etc/ld.so.conf`` (or in |
| 156 | ``/etc/ld.so.conf.d``) **before** running ``sudo ldconfig``. For example:: |
| 157 | |
| 158 | echo /usr/local/lib | sudo tee /etc/ld.so.conf.d/ndn-cxx.conf |
| 159 | |
| 160 | Alternatively, ``LD_LIBRARY_PATH`` environment variable should be set to the location of |
| 161 | the library:: |
| 162 | |
| 163 | export LD_LIBRARY_PATH=/usr/local/lib |
| 164 | |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 165 | This builds and installs the following items: |
| 166 | |
Alexander Afanasyev | 7ed2943 | 2015-06-05 18:01:16 -0700 | [diff] [blame] | 167 | - ``<LIBPATH>/libndn-cxx.a``: static NDN C++ library (if enabled) |
| 168 | - ``<LIBPATH>/libndn-cxx.so``, ``<LIBPATH>/libndn-cxx.so.<VERSION>`` (on Linux), |
| 169 | ``<LIBPATH>/libndn-cxx.dylib``, ``<LIBPATH>/libndn-cxx.<VERSION>.dylib`` (on OS X): |
| 170 | shared NDN C++ library (if enabled) |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 171 | - ``<LIBPATH>/pkgconfig/libndn-cxx.pc``: pkgconfig file storing all |
| 172 | neccessary flags to build against the library. For example, if |
| 173 | pkgconfig or pkgconf package is installed and ``PKG_CONFIG_PATH`` is |
| 174 | configured properly (or ``<LIBPATH>/pkgconfig`` is a default path), |
| 175 | ``pkgconfig --libs --clflags libndn-cxx`` will return all necessary |
| 176 | compile and link flags for the library. |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 177 | - ``<BINPATH>/ndnsec``: tool to manage NDN keys and certificates |
| 178 | - ``<BINPATH>/ndnsec-*``: convenience scripts for ``ndnsec`` tools |
| 179 | |
| 180 | If configured with tests: ``./waf configure --with-tests``), the above |
| 181 | commands will also produce: |
| 182 | |
| 183 | - ``build/unit-tests``: A unit test binary for the library |
| 184 | |
Junxiao Shi | e04bd83 | 2014-11-29 23:02:38 -0700 | [diff] [blame] | 185 | 1.5GB available memory per CPU core is necessary for efficient compilation. |
| 186 | On a multi-core machine with less than 1.5GB available memory per CPU core, |
| 187 | limit the objects being compiled in parallel with ``./waf -jN`` where N is the amount |
| 188 | of available memory divided by 1.5GB (eg. ``./waf -j1`` for 1.5GB memory), |
| 189 | which could usually avoid memory thrashing and result in faster compilation. |
| 190 | |
Alexander Afanasyev | c8bcd45 | 2014-05-12 17:58:47 -0700 | [diff] [blame] | 191 | Build with examples |
| 192 | ------------------- |
| 193 | |
| 194 | By default, examples in ``examples/`` are not build. To enable them, use |
| 195 | ``--with-examples`` configure option: |
| 196 | |
| 197 | :: |
| 198 | |
| 199 | ./waf configure --with-examples |
| 200 | ./waf |
Alexander Afanasyev | 7ed2943 | 2015-06-05 18:01:16 -0700 | [diff] [blame] | 201 | sudo ./waf install |
| 202 | |
| 203 | :ref:`Additional step <build>`: |
| 204 | |
| 205 | - on Linux:: |
| 206 | |
| 207 | sudo ldconfig |
| 208 | |
| 209 | - on FreeBSD:: |
| 210 | |
| 211 | sudo ldconfig -m |
Alexander Afanasyev | c8bcd45 | 2014-05-12 17:58:47 -0700 | [diff] [blame] | 212 | |
| 213 | To run examples: |
| 214 | |
| 215 | :: |
| 216 | |
| 217 | # trivial producer app |
| 218 | ./build/examples/producer |
| 219 | |
| 220 | # trivial consumer app |
| 221 | ./build/examples/consumer |
| 222 | |
| 223 | # trivial consumer app with timers |
| 224 | ./build/examples/consumer-with-timer |
| 225 | |
| 226 | If you want to test out a sample application, just create a ``.cpp`` file in ``examples/`` |
| 227 | folder and it will be compiled on the next run on ``./waf``. For example: |
| 228 | |
| 229 | :: |
| 230 | |
| 231 | cp examples/consumer.cpp examples/my-new-consumer-app.cpp |
| 232 | ./waf |
Alexander Afanasyev | 7ed2943 | 2015-06-05 18:01:16 -0700 | [diff] [blame] | 233 | sudo ./waf install |
Alexander Afanasyev | c8bcd45 | 2014-05-12 17:58:47 -0700 | [diff] [blame] | 234 | ./build/examples/my-new-consumer-app |
| 235 | |
| 236 | |
Alexander Afanasyev | 9b0e114 | 2014-05-08 00:17:34 -0700 | [diff] [blame] | 237 | Debug symbols |
| 238 | ~~~~~~~~~~~~~ |
| 239 | |
| 240 | The default compiler flags enable debug symbols to be included in binaries (i.e., ``-g`` |
| 241 | flag for ``./waf configure`` and ``-g3`` for ``./waf configure --debug``). This |
| 242 | potentially allows more meaningful debugging information if your application crashes. |
| 243 | |
| 244 | If it is undesirable, default flags can be easily overridden: |
| 245 | |
| 246 | :: |
| 247 | |
| 248 | CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc |
| 249 | ./waf |
| 250 | sudo ./waf install |
| 251 | |
Alexander Afanasyev | 7ed2943 | 2015-06-05 18:01:16 -0700 | [diff] [blame] | 252 | :ref:`Additional step <build>`: |
| 253 | |
| 254 | - on Linux:: |
| 255 | |
| 256 | sudo ldconfig |
| 257 | |
| 258 | - on FreeBSD:: |
| 259 | |
| 260 | sudo ldconfig -m |
| 261 | |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 262 | Documentation |
| 263 | ------------- |
| 264 | |
| 265 | ndn-cxx tutorials and API documentation can be built using the following |
| 266 | commands: |
| 267 | |
| 268 | :: |
| 269 | |
| 270 | # Full set of documentation (tutorials + API) in build/docs |
| 271 | ./waf docs |
| 272 | |
| 273 | # Only tutorials in `build/docs` |
| 274 | ./waf sphinx |
| 275 | |
| 276 | # Only API docs in `build/docs/doxygen` |
| 277 | ./waf doxgyen |
| 278 | |
| 279 | Manpages are automatically created and installed during the normal build |
| 280 | process (e.g., during ``./waf`` and ``./waf install``), if |
| 281 | ``python-sphinx`` module is detected during ``./waf configure`` stage. |
| 282 | By default, manpages are installed into ``${PREFIX}/share/man`` (where |
| 283 | default value for ``PREFIX`` is ``/usr/local``). This location can be |
| 284 | changed during ``./waf configure`` stage using ``--prefix``, |
| 285 | ``--datarootdir``, or ``--mandir`` options. |
| 286 | |
| 287 | For more details, refer to ``./waf --help``. |
| 288 | |
| 289 | Development Build |
| 290 | ----------------- |
| 291 | |
| 292 | The following is the suggested configure commands for development build. |
| 293 | |
| 294 | :: |
| 295 | |
| 296 | ./waf configure --debug --with-tests |
| 297 | ./waf |
| 298 | sudo ./waf install |
| 299 | |
Alexander Afanasyev | 7ed2943 | 2015-06-05 18:01:16 -0700 | [diff] [blame] | 300 | :ref:`Additional step <build>`: |
| 301 | |
| 302 | - on Linux:: |
| 303 | |
| 304 | sudo ldconfig |
| 305 | |
| 306 | - on FreeBSD:: |
| 307 | |
| 308 | sudo ldconfig -m |
| 309 | |
Alexander Afanasyev | c5452c5 | 2014-04-29 17:21:51 -0700 | [diff] [blame] | 310 | In the development build all compiler optimizations are disabled by |
| 311 | default and all warnings are treated as error. The default behavior can |
| 312 | be overridden by setting ``CXXFLAGS`` environment variable before |
| 313 | running ``./waf configure``: |
| 314 | |
| 315 | :: |
| 316 | |
| 317 | CXXFLAGS="-O1 -g3" ./waf configure --debug --with-tests |
| 318 | ... |
Alexander Afanasyev | 5946ed1 | 2015-01-19 23:41:39 -0800 | [diff] [blame] | 319 | |
| 320 | Customize Compiler |
| 321 | ------------------ |
| 322 | |
Davide Pesavento | 0530b5b | 2016-11-07 03:23:58 +0100 | [diff] [blame] | 323 | To choose a custom C++ compiler for building ndn-cxx, set ``CXX`` environment |
| 324 | variable to point to the compiler binary. For example, to build with clang on |
| 325 | Linux, use the following: |
Alexander Afanasyev | 5946ed1 | 2015-01-19 23:41:39 -0800 | [diff] [blame] | 326 | |
| 327 | :: |
| 328 | |
Davide Pesavento | 0530b5b | 2016-11-07 03:23:58 +0100 | [diff] [blame] | 329 | CXX=clang++ ./waf configure |