-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCompiling_client_applications.html
More file actions
389 lines (363 loc) · 29.5 KB
/
Compiling_client_applications.html
File metadata and controls
389 lines (363 loc) · 29.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>3. Compiling client applications — Anjay 3.13.1 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/copybutton.css" type="text/css" />
<link rel="stylesheet" href="_static/sphinx-design.min.css" type="text/css" />
<link rel="stylesheet" href="_static/theme_overrides.css" type="text/css" />
<link rel="canonical" href="https://docs.avsystem.com/hubfs/Anjay_Docs/Compiling_client_applications.html" />
<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=ced7c45e"></script>
<script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/clipboard.min.js?v=a7894cd8"></script>
<script src="_static/copybutton.js?v=f281be69"></script>
<script src="_static/design-tabs.js?v=f930bc37"></script>
<script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="4. Basic client" href="BasicClient.html" />
<link rel="prev" title="2. OMA LwM2M - Brief description" href="LwM2M.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" style="background: #ffd500" >
<a href="index.html">
<img src="_static/avsystem_header.png" class="logo" alt="Logo"/>
</a>
<div class="version">
3.13.1
</div><div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search Documentation..." />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="Introduction.html">1. Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="LwM2M.html">2. OMA LwM2M - Brief description</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">3. Compiling client applications</a></li>
<li class="toctree-l1"><a class="reference internal" href="BasicClient.html">4. Basic client</a></li>
<li class="toctree-l1"><a class="reference internal" href="AdvancedTopics.html">5. Advanced topics</a></li>
<li class="toctree-l1"><a class="reference internal" href="FirmwareUpdateTutorial.html">6. Firmware Update Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="LwM2MGateway.html">7. LwM2M Gateway</a></li>
<li class="toctree-l1"><a class="reference internal" href="Tools.html">8. Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="KnownIssues.html">9. Known Issues</a></li>
<li class="toctree-l1"><a class="reference internal" href="PortingGuideForNonPOSIXPlatforms.html">10. Porting guide for non-POSIX platforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="Migrating.html">11. Migrating from older versions</a></li>
<li class="toctree-l1"><a class="reference internal" href="CommercialFeatures.html">12. Commercial features</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="APIReference.html">API Reference</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" style="background: #ffd500" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Anjay</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active"><span class="section-number">3. </span>Compiling client applications</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="compiling-client-applications">
<h1><span class="section-number">3. </span>Compiling client applications<a class="headerlink" href="#compiling-client-applications" title="Link to this heading"></a></h1>
<section id="compiling-the-library">
<h2><span class="section-number">3.1. </span>Compiling the library<a class="headerlink" href="#compiling-the-library" title="Link to this heading"></a></h2>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>If you cloned Anjay from a Git repository, ensure that you updated
submodules by calling <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">submodule</span> <span class="pre">update</span> <span class="pre">--init</span></code> before continuing.</p>
</div>
<p>Anjay uses CMake for project configuration. To compile the library with default
settings, call the following command in Anjay root directory:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cmake<span class="w"> </span>.<span class="w"> </span><span class="o">&&</span><span class="w"> </span>make
</pre></div>
</div>
</section>
<section id="cross-compiling">
<h2><span class="section-number">3.2. </span>Cross-compiling<a class="headerlink" href="#cross-compiling" title="Link to this heading"></a></h2>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Cross-compilation is necessary only if you are compiling the library to use
on a different system, than the one used for compilation. If you, for
example, want to use Anjay on Raspberry Pi, then you can perform
compilation on Raspberry Pi as described above or cross-compilation on your
PC.</p>
</div>
<section id="arm-cortex-m3-powered-stm3220">
<h3><span class="section-number">3.2.1. </span>ARM Cortex-M3-powered STM3220<a class="headerlink" href="#arm-cortex-m3-powered-stm3220" title="Link to this heading"></a></h3>
<p>First, prepare a CMake toolchain file (see <a class="reference external" href="https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html#cross-compiling">CMake documentation</a>), then pass <code class="code docutils literal notranslate"><span class="pre">CMAKE_TOOLCHAIN_FILE</span></code> when configuring Anjay:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cmake<span class="w"> </span>-DCMAKE_TOOLCHAIN_FILE<span class="o">=</span><span class="nv">$YOUR_TOOLCHAIN_FILE</span><span class="w"> </span>.<span class="w"> </span><span class="o">&&</span><span class="w"> </span>make
</pre></div>
</div>
<p>An example CMake toolchain file for an ARM Cortex-M3-powered STM3220 platform may look like so:</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nb">set</span><span class="p">(</span><span class="s">CMAKE_SYSTEM_NAME</span><span class="w"> </span><span class="s">Generic</span><span class="p">)</span>
<span class="nb">set</span><span class="p">(</span><span class="s">CMAKE_SYSTEM_VERSION</span><span class="w"> </span><span class="s">1</span><span class="p">)</span>
<span class="nb">set</span><span class="p">(</span><span class="s">CMAKE_C_COMPILER</span><span class="w"> </span><span class="s">arm-none-eabi-gcc</span><span class="p">)</span>
<span class="c"># CMAKE_C_FLAGS set in a toolchain file get overwritten by CMakeCInformation.cmake</span>
<span class="c"># unless they are FORCEfully set in the cache</span>
<span class="c"># See http://stackoverflow.com/a/30217088/2339636</span>
<span class="nb">unset</span><span class="p">(</span><span class="s">CMAKE_C_FLAGS</span><span class="w"> </span><span class="s">CACHE</span><span class="p">)</span>
<span class="nb">set</span><span class="p">(</span><span class="s">CMAKE_C_FLAGS</span><span class="w"> </span><span class="s2">"-mcpu=cortex-m3 -mthumb -msoft-float -ffunction-sections -fdata-sections -fno-common -fmessage-length=0 -std=gnu99 --specs=nosys.specs"</span><span class="w"> </span><span class="s">CACHE</span><span class="w"> </span><span class="s">STRING</span><span class="w"> </span><span class="s2">""</span><span class="w"> </span><span class="s">FORCE</span><span class="p">)</span>
<span class="nb">set</span><span class="p">(</span><span class="s">CMAKE_EXE_LINKER_FLAGS</span><span class="w"> </span><span class="s2">"-Wl,-gc-sections"</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="android">
<h3><span class="section-number">3.2.2. </span>Android<a class="headerlink" href="#android" title="Link to this heading"></a></h3>
<p>Compilation on Android platform is rather straightforward. First you have to get <a class="reference external" href="https://developer.android.com/ndk/index.html">Android NDK</a>. To configure Anjay you
have to pass <code class="docutils literal notranslate"><span class="pre">CMAKE_TOOLCHAIN_FILE</span></code> from the NDK (we assume that
<code class="docutils literal notranslate"><span class="pre">ANDROID_NDK</span></code> variable contains a path to the folder where Android NDK
is extracted):</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cmake<span class="w"> </span>-DCMAKE_TOOLCHAIN_FILE<span class="o">=</span><span class="nv">$ANDROID_NDK</span>/build/cmake/android.toolchain.cmake<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DDTLS_BACKEND<span class="o">=</span><span class="s2">""</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DANDROID_ALLOW_UNDEFINED_SYMBOLS<span class="o">=</span>ON<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DANDROID_PLATFORM<span class="o">=</span>android-18<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DANDROID_ABI<span class="o">=</span>armeabi<span class="w"> </span>.
</pre></div>
</div>
<p>After that Anjay can be compiled as usual via <cite>make</cite>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Android platforms older than <cite>android-18</cite> are not supported.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p><code class="docutils literal notranslate"><span class="pre">ANDROID_ALLOW_UNDEFINED_SYMBOLS</span></code> is set, so that unresolved symbols
required by the <cite>libanjay.so</cite> are not reported during the linking
stage. They shall be resolved by providing dependencies to the final
executable as it is illustrated in the next section.</p>
</div>
<p>Note that we did not set any <code class="docutils literal notranslate"><span class="pre">DTLS_BACKEND</span></code> and therefore Anjay is compiled
without DTLS support. To enable DTLS support you have to provide a value
to <code class="docutils literal notranslate"><span class="pre">DTLS_BACKEND</span></code> (see <a class="reference external" href="https://github.com/AVSystem/Anjay">README.md</a>
for more details) along with specific variable indicating where the required
DTLS libraries are to be found, i.e. one of:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">OPENSSL_ROOT_DIR</span></code> (as <cite>FindOpenSSL.cmake</cite> suggests),</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">MBEDTLS_ROOT_DIR</span></code>,</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">TINYDTLS_ROOT_DIR</span></code></p></li>
</ul>
</div></blockquote>
<p>depending on the chosen backend.</p>
<aside class="topic">
<p class="topic-title">Example compilation with mbed TLS backend</p>
<p>First, we compile mbed TLS on Android:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span>git<span class="w"> </span>clone<span class="w"> </span>https://github.com/ARMmbed/mbedtls<span class="w"> </span>-b<span class="w"> </span>mbedtls-2.5.0
$<span class="w"> </span><span class="nb">cd</span><span class="w"> </span>mbedtls
$<span class="w"> </span>cmake<span class="w"> </span>-DCMAKE_TOOLCHAIN_FILE<span class="o">=</span><span class="nv">$ANDROID_NDK</span>/build/cmake/android.toolchain.cmake<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DANDROID_PLATFORM<span class="o">=</span>android-18<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DANDROID_ABI<span class="o">=</span>armeabi<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DENABLE_TESTING<span class="o">=</span>OFF<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DCMAKE_INSTALL_PREFIX<span class="o">=</span>/tmp/mbedtls/install<span class="w"> </span>.
$<span class="w"> </span>make
$<span class="w"> </span>make<span class="w"> </span>install
</pre></div>
</div>
<p>We then go back to the Anjay source directory, to reconfigure Anjay to use
mbed TLS binaries (we strongly suggest to clean all kind of CMake caches
before proceeding, as it may not work otherwise):</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cmake<span class="w"> </span>-DCMAKE_TOOLCHAIN_FILE<span class="o">=</span><span class="nv">$ANDROID_NDK</span>/build/cmake/android.toolchain.cmake<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DDTLS_BACKEND<span class="o">=</span><span class="s2">"mbedtls"</span><span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DMBEDTLS_ROOT_DIR<span class="o">=</span>/tmp/mbedtls/install<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DANDROID_ALLOW_UNDEFINED_SYMBOLS<span class="o">=</span>ON<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DANDROID_PLATFORM<span class="o">=</span>android-18<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>-DANDROID_ABI<span class="o">=</span>armeabi<span class="w"> </span>.
</pre></div>
</div>
<p>And finally, we run <cite>make</cite>, finishing the whole procedure.</p>
</aside>
</section>
</section>
<section id="installing-the-library">
<h2><span class="section-number">3.3. </span>Installing the library<a class="headerlink" href="#installing-the-library" title="Link to this heading"></a></h2>
<section id="building-with-cmake">
<h3><span class="section-number">3.3.1. </span>Building with CMake<a class="headerlink" href="#building-with-cmake" title="Link to this heading"></a></h3>
<p>The preferred way of building Anjay is to use CMake.</p>
<p>To install Anjay headers and libraries in <code class="code docutils literal notranslate"><span class="pre">/usr/local</span></code>:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cmake<span class="w"> </span>.<span class="w"> </span><span class="o">&&</span><span class="w"> </span>make<span class="w"> </span><span class="o">&&</span><span class="w"> </span>sudo<span class="w"> </span>make<span class="w"> </span>install
</pre></div>
</div>
<p>A custom installation prefix may be set using <code class="code docutils literal notranslate"><span class="pre">CMAKE_INSTALL_PREFIX</span></code>:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cmake<span class="w"> </span>-DCMAKE_INSTALL_PREFIX<span class="o">=</span>/custom/path<span class="w"> </span>.<span class="w"> </span><span class="o">&&</span><span class="w"> </span>make<span class="w"> </span><span class="o">&&</span><span class="w"> </span>make<span class="w"> </span>install
</pre></div>
</div>
</section>
<section id="alternative-build-systems">
<span id="no-cmake"></span><h3><span class="section-number">3.3.2. </span>Alternative build systems<a class="headerlink" href="#alternative-build-systems" title="Link to this heading"></a></h3>
<p>Alternatively, you may use any other build system. You will need to:</p>
<ul class="simple">
<li><p>Prepare your <code class="docutils literal notranslate"><span class="pre">avs_commons_config.h</span></code>, <code class="docutils literal notranslate"><span class="pre">avs_coap_config.h</span></code> and <code class="docutils literal notranslate"><span class="pre">anjay_config.h</span></code> files.</p>
<ul>
<li><p>Comments in <a class="reference external" href="https://github.com/AVSystem/avs_commons/blob/master/include_public/avsystem/commons/avs_commons_config.h.in">avs_commons_config.h.in</a>,
<a class="reference external" href="https://github.com/AVSystem/Anjay/blob/master/deps/avs_coap/include_public/avsystem/coap/avs_coap_config.h.in">avs_coap_config.h.in</a>
and <a class="reference external" href="https://github.com/AVSystem/Anjay/blob/master/include_public/anjay/anjay_config.h.in">anjay_config.h.in</a>
will guide you about the meaning of various settings.</p></li>
<li><p>You may use one of the directories from <a class="reference external" href="https://github.com/AVSystem/Anjay/tree/master/example_configs">example_configs</a> as a starting point. See
<a class="reference external" href="https://github.com/AVSystem/Anjay/blob/master/example_configs/README.md">README.md inside that directory</a> for details. You may
even set one of the subdirectories there are as an include path directly in your compiler if you
do not need any customizations.</p></li>
</ul>
</li>
<li><p>Configure your build system so that:</p>
<ul>
<li><p>At least all <code class="docutils literal notranslate"><span class="pre">*.c</span></code> and <code class="docutils literal notranslate"><span class="pre">*.h</span></code> files from <code class="docutils literal notranslate"><span class="pre">src</span></code>, <code class="docutils literal notranslate"><span class="pre">include_public</span></code>, <code class="docutils literal notranslate"><span class="pre">deps/avs_coap/src</span></code>,
<code class="docutils literal notranslate"><span class="pre">deps/avs_coap/include_public</span></code>, <code class="docutils literal notranslate"><span class="pre">deps/avs_commons/src</span></code> and
<code class="docutils literal notranslate"><span class="pre">deps/avs_commons/include_public</span></code> directories are preserved, with the directory structure
intact.</p>
<ul>
<li><p>It is also safe to merge contents of all <code class="docutils literal notranslate"><span class="pre">include_public</span></code> directories into one. Merging
<code class="docutils literal notranslate"><span class="pre">src</span></code> directories should be safe, too, but is not explicitly supported.</p></li>
</ul>
</li>
<li><p>All <code class="docutils literal notranslate"><span class="pre">*.c</span></code> files inside <code class="docutils literal notranslate"><span class="pre">src</span></code>, <code class="docutils literal notranslate"><span class="pre">deps/avs_coap/src</span></code>, <code class="docutils literal notranslate"><span class="pre">deps/avs_commons/src</span></code>, or any of
their direct or indirect subdirectories are compiled.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">deps/avs_commons/src</span></code> and <code class="docutils literal notranslate"><span class="pre">deps/avs_commons/include_public</span></code> directories are included in the
header search path when compiling <code class="docutils literal notranslate"><span class="pre">avs_commons</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">deps/avs_coap/src</span></code>, <code class="docutils literal notranslate"><span class="pre">deps/avs_coap/include_public</span></code> and <code class="docutils literal notranslate"><span class="pre">deps/avs_commons/include_public</span></code>
directories are included in the header search path when compiling <code class="docutils literal notranslate"><span class="pre">avs_coap</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">src</span></code>, <code class="docutils literal notranslate"><span class="pre">include_public</span></code>, <code class="docutils literal notranslate"><span class="pre">deps/avs_coap/include_public</span></code> and
<code class="docutils literal notranslate"><span class="pre">deps/avs_commons/include_public</span></code> directories are included in the header search path when
compiling Anjay.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">include_public</span></code>, <code class="docutils literal notranslate"><span class="pre">deps/avs_coap/include_public</span></code> and <code class="docutils literal notranslate"><span class="pre">deps/avs_commons/include_public</span></code>
directories, or copies of them (possibly merged into one directory) are included in the header
search path when compiling dependent application code.</p></li>
</ul>
</li>
</ul>
<p class="rubric">Example</p>
<p>Below is an example of a simplistic build process, that builds all of avs_commons, avs_coap and
Anjay from a Unix-like shell:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># configuration</span>
cp<span class="w"> </span>-r<span class="w"> </span>example_configs/linux_lwm2m10<span class="w"> </span>config
<span class="c1"># you may want to edit the files in the "config" directory before continuing</span>
<span class="c1"># compilation</span>
cc<span class="w"> </span>-Iconfig<span class="w"> </span>-Iinclude_public<span class="w"> </span>-Ideps/avs_coap/include_public<span class="w"> </span>-Ideps/avs_commons/include_public<span class="w"> </span>-Isrc<span class="w"> </span>-Ideps/avs_coap/src<span class="w"> </span>-Ideps/avs_commons/src<span class="w"> </span>-c<span class="w"> </span><span class="k">$(</span>find<span class="w"> </span>src<span class="w"> </span>deps/avs_coap/src<span class="w"> </span>deps/avs_commons/src<span class="w"> </span>-name<span class="w"> </span><span class="s1">'*.c'</span><span class="k">)</span>
ar<span class="w"> </span>rcs<span class="w"> </span>libanjay.a<span class="w"> </span>*.o
<span class="c1"># installation</span>
cp<span class="w"> </span>libanjay.a<span class="w"> </span>/usr/local/lib/
cp<span class="w"> </span>-r<span class="w"> </span>include_public/avsystem<span class="w"> </span>/usr/local/include/
cp<span class="w"> </span>-r<span class="w"> </span>deps/avs_coap/include_public/avsystem<span class="w"> </span>/usr/local/include/
cp<span class="w"> </span>-r<span class="w"> </span>deps/avs_commons/include_public/avsystem<span class="w"> </span>/usr/local/include/
cp<span class="w"> </span>-r<span class="w"> </span>config/*<span class="w"> </span>/usr/local/include/
</pre></div>
</div>
</section>
</section>
<section id="including-the-library-in-an-application">
<h2><span class="section-number">3.4. </span>Including the library in an application<a class="headerlink" href="#including-the-library-in-an-application" title="Link to this heading"></a></h2>
<section id="cmake-projects">
<h3><span class="section-number">3.4.1. </span>CMake projects<a class="headerlink" href="#cmake-projects" title="Link to this heading"></a></h3>
<p>The preferred method of using Anjay in custom projects is to use CMake <code class="code docutils literal notranslate"><span class="pre">find_package</span></code> command after installing the library:</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nb">find_package</span><span class="p">(</span><span class="s">anjay</span><span class="p">)</span>
<span class="nb">include_directories</span><span class="p">(</span><span class="o">${</span><span class="nv">ANJAY_INCLUDE_DIRS</span><span class="o">}</span><span class="p">)</span>
<span class="nb">target_link_libraries</span><span class="p">(</span><span class="s">my_executable</span><span class="w"> </span><span class="o">${</span><span class="nv">ANJAY_LIBRARIES</span><span class="o">}</span><span class="p">)</span><span class="w"> </span><span class="c"># or ANJAY_LIBRARIES_STATIC for a static library</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If a custom installation path is used, you need to set <code class="code docutils literal notranslate"><span class="pre">anjay_DIR</span></code> CMake variable to <code class="code docutils literal notranslate"><span class="pre">$YOUR_INSTALL_PREFIX/lib/anjay</span></code>.</p>
</div>
</section>
<section id="id1">
<h3><span class="section-number">3.4.2. </span>Alternative build systems<a class="headerlink" href="#id1" title="Link to this heading"></a></h3>
<p>If Anjay itself has been compiled using CMake, flags necessary for other build systems can be
retrieved using <code class="code docutils literal notranslate"><span class="pre">cmake</span></code> command:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cmake<span class="w"> </span>--find-package<span class="w"> </span>-DNAME<span class="o">=</span>anjay<span class="w"> </span>-DLANGUAGE<span class="o">=</span>C<span class="w"> </span>-DCOMPILER_ID<span class="o">=</span>Generic<span class="w"> </span>-DMODE<span class="o">=</span><mode>
</pre></div>
</div>
<p>Where <code class="code docutils literal notranslate"><span class="pre"><mode></span></code> is one of:</p>
<ul class="simple">
<li><p><code class="code docutils literal notranslate"><span class="pre">EXIST</span></code> - check whether the library can be found,</p></li>
<li><p><code class="code docutils literal notranslate"><span class="pre">COMPILE</span></code> - print compilation flags,</p></li>
<li><p><code class="code docutils literal notranslate"><span class="pre">LINK</span></code> - print linking arguments.</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If a custom installation prefix is used, you need to also pass <code class="code docutils literal notranslate"><span class="pre">-Danjay_DIR=$YOUR_INSTALL_PREFIX/lib/anjay</span></code>.</p>
</div>
</section>
<section id="anjay-compiled-without-cmake">
<h3><span class="section-number">3.4.3. </span>Anjay compiled without CMake<a class="headerlink" href="#anjay-compiled-without-cmake" title="Link to this heading"></a></h3>
<p>If Anjay has been compiled without using CMake, you will need to provide necessary flags manually.</p>
<p>Specific dependencies will vary according to:</p>
<ul class="simple">
<li><p>compile-time configuration, including:</p>
<ul>
<li><p>avs_compat_threading backend</p></li>
<li><p>avs_crypto backend, if any</p></li>
<li><p>avs_net DTLS backend, if any</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">AVS_COMMONS_HTTP_WITH_ZLIB</span></code> setting, if avs_http is enabled</p></li>
</ul>
</li>
<li><p>target platform</p></li>
<li><p>build environment</p></li>
</ul>
<p class="rubric">Example</p>
<p>For the following conditions:</p>
<ul class="simple">
<li><p>Anjay compiled with all optional features enabled, and:</p>
<ul>
<li><p>mbed TLS security enabled as avs_net DTLS backend and/or avs_crypto backend</p></li>
<li><p>PThread used as avs_compat_threading backend</p></li>
<li><p>avs_http enabled with zlib support</p></li>
</ul>
</li>
<li><p>Target platform being a typical desktop GNU/Linux distribution</p></li>
<li><p>GCC or Clang used as the compiler</p></li>
<li><p>Anjay compiled and installed as shown in the example in the <a class="reference internal" href="#no-cmake"><span class="std std-ref">Alternative build systems</span></a> section</p></li>
</ul>
<p>the flags necessary to link client applications would be:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>-lanjay<span class="w"> </span>-lz<span class="w"> </span>-lmbedtls<span class="w"> </span>-lmbedcrypto<span class="w"> </span>-lmbedx509<span class="w"> </span>-lm<span class="w"> </span>-pthread
</pre></div>
</div>
</section>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="LwM2M.html" class="btn btn-neutral float-left" title="2. OMA LwM2M - Brief description" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="BasicClient.html" class="btn btn-neutral float-right" title="4. Basic client" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>© Copyright 2026, AVSystem.</p>
</div>
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
<script type="text/javascript" id="hs-script-loader" async defer src="//js-eu1.hs-scripts.com/139620700.js"></script>
</body>
</html>