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