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