• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1For Windows builds - see the Windows Section
2
3Obtaining the Libcoap Source
4============================
5
6To get the libcoap library source, you need to do either the following
7
8* Obtain the latest distribution package file from
9  https://github.com/obgm/libcoap/archive/develop.zip
10  [There is a stable version at
11   https://github.com/obgm/libcoap/archive/main.zip]
12* Change to the directory that you want to install the libcoap sub-directory
13  into
14* Unpack the distribution package file
15* Change into the top level directory of the unpackaged files
16
17or alternatively, clone the libcoap git repository from github
18
19* Change to the directory that you want to install the libcoap sub-directory
20  into.
21* Then clone the latest (develop) version of the code:-
22   git clone https://github.com/obgm/libcoap.git
23* Change into the top level directory of the cloned files
24* Optionally, change the branch from develop to the stable main branch:-
25   git checkout main
26
27Building Libcoap Libraries and Examples
28=======================================
29
30Follow the appropriate sections below
31
32
33TinyDTLS Only
34=============
35
36It is possible that you may need to execute the following two commands once to
37get the TinyDTLS code into your project, so the TinyDTLS library can be used.
38
39 git submodule init
40 git submodule update
41
42General Building with cmake for linux/windows/macos/android (not for RIOT, LwIP or Contiki-NG - see below)
43================
44
45 cmake -E remove_directory build
46 cmake -E make_directory build
47 cd build
48 cmake .. -DENABLE_TESTS=ON
49 cmake --build .
50 [sudo] cmake --build . -- install
51 cd ..
52
53 Note: to see possible options (TLS lib, doc, tests, examples etc.):
54 cmake -LH build
55
56 Note: For Windows, this is supported by Visual Studio Code with CMake extension
57 Note: You must use cmake version >=3.10.
58
59 Note: you can use cmake's find package after installation: find_package(libcoap-3 REQUIRED),
60 and target_link_libraries(myTarget PRIVATE libcoap::coap-2)
61
62 Note: Shared Library support is not currently available for Windows.
63
64General Building with autoconf (not for RIOT, LwIP or Contiki-NG - see below)
65================
66
67 ./autogen.sh
68 ./configure
69 make
70 sudo make install
71
72./autogen.sh will fail if there is a required package for buildling libcoap
73that is missing. Install the missing package and try ./autogen.sh again.
74
75It is possible that you may need to provide some options to ./configure
76to customize your installation.
77
78In particular you may need to define which (D)TLS library to use as well as
79disable some building of documentation.
80
81General configure instructions can be found in INSTALL, which is built
82by ./autogen.sh
83
84 ./configure --help
85gives the specific options available to libcoap.
86
87Some examples are:-
88
89# No DTLS
90 ./configure --enable-tests --disable-documentation --enable-examples --disable-dtls --enable-shared
91
92# With TinyDTLS
93 ./configure --enable-tests --disable-documentation --enable-examples --with-tinydtls --enable-shared
94
95Note: FreeBSD requires gmake instead of make when building TinyDTLS - i.e.
96 gmake
97 sudo gmake install
98
99# With OpenSSL
100 ./configure --with-openssl --enable-tests --enable-shared
101
102# With GnuTLS
103 ./configure --with-gnutls --enable-tests --enable-shared
104
105Note: --disable-documentation disables the building of doxygen and man page
106files.  If you want to only disable one of them, use --disable-doxygen or
107--disable-manpages.  Doxygen requires the program doxygen and man pages require
108the program a2x to build the appropriate files.
109
110If you need to rebuild the libcoap-*.{map,sym} files to update any exposed
111function changes, run
112
113 make update-map-file
114
115prior to running 'make'.
116
117RIOT
118====
119
120 ./autogen.sh
121 ./configure --disable-tests --disable-documentation --disable-examples --disable-dtls
122 cd examples/riot
123 make
124
125See examples/riot/README for further information.
126
127LwIP
128====
129
130 ./autogen.sh
131 ./configure --disable-tests --disable-documentation --disable-examples --disable-dtls
132 cd examples/lwip
133 make
134
135Executable is ./server. See examples/lwip/README for further information.
136
137Contiki-NG
138==========
139
140 ./autogen.sh
141 ./configure --disable-tests --disable-documentation --disable-examples --disable-dtls
142 cd examples/contiki
143 make
144
145Executable is ./server.native. See examples/contiki/README for further
146information.
147
148Windows
149=======
150
151Install OpenSSL (minimum version 1.1.0) including the development libraries if
152not already installed.
153
154Within Visual Studio, "Clone or check out code" using the repository
155https://github.com/obgm/libcoap.git
156
157You may need to update the SDK version of the libcoap Windows Project files to
158match that of the SDK version of the Visual Studio you are using.  In Solution
159Explorer with the view set to libcoap.sln, right click "Solution 'libcoap'"
160and then "Retarget solution".
161
162You may need to edit win32\libcoap.props to update the OpenSSLRootDir and
163OpenSSLRootDirDbg variables to point to the top level directory where OpenSSL
164is installed so that the include, lib etc. directories are correctly set up.
165Note: Make sure that you include a trailing \ in the variable definitions.
166
167Alternatively you can build everything in Visual Studio with CMake.
168
169MinGW
170=====
171
172As there are many ways to install MinGW, depending on the different
173installed packages, random failures can occur (usually because of conflicts
174with cygwin based packages).  Below is a way known to work with libcoap
175on a Windows host.
176
177Remove any old copy of MSYS2 using Windows program remove.
178
179Download https://repo.msys2.org/distrib/x86_64/msys2-x86_64-20230318.exe and
180run the executable, accepting the defaults.
181
182In a UCRT64 window, add in the following packages
183
184 pacman -S git
185 pacman -S vim
186 pacman -S mingw-w64-ucrt-x86_64-cmake
187 pacman -S mingw-w64-ucrt-x86_64-gcc
188 pacman -S mingw-w64-ucrt-x86_64-openssl
189
190Alternatively, in a MINGW64 window, add in the following packages
191
192 pacman -S git
193 pacman -S vim
194 pacman -S mingw-w64-x86_64-cmake
195 pacman -S mingw-w64-x86_64-gcc
196 pacman -S mingw-w64-x86_64-openssl
197
198Then clone a copy of the github libcoap repository in a UCRT64 or MINGW64 window
199
200 git clone https://github.com/obgm/libcoap.git
201 cd libcoap
202
203Then build the libcoap library and example executables (which will be in the
204build directory)
205
206 cmake -E remove_directory build
207 cmake -E make_directory build
208 cd build
209 cmake .. -DENABLE_DOCS=OFF -DDTLS_BACKEND=openssl
210 cmake --build .
211