Building from Source
Warning
libiio v1, available in the main branch, is under heavy active development. If you are looking for a stable version, please use the latest release by checking out a tag starting with v0.. For example, to check out the v0.25 release, use the following command:
git checkout v0.25
This section describes how to build libiio from source. This is useful if you want to use the latest features or if you are developing libiio itself.
Install Prerequisites/Dependencies and Build
Basic system setup
analog@precision:~$ sudo apt-get update
analog@precision:~$ sudo apt-get install build-essential
Install Prerequisites
analog@precision:~$ sudo apt-get install libxml2-dev libzstd-dev bison flex libcdk5-dev cmake
Install libraries for Backends
analog@precision:~$ sudo apt-get install libaio-dev libusb-1.0-0-dev
analog@precision:~$ sudo apt-get install libserialport-dev libavahi-client-dev
Install to build doc
analog@precision:~$ sudo apt-get install doxygen graphviz
Install to build python backends
analog@precision:~$ sudo apt-get install python3 python3-pip python3-setuptools
Clone
analog@precision:~$ git clone https://github.com/analogdevicesinc/libiio.git
analog@precision:~$ cd libiio
Build
analog@precision:~/libiio$ mkdir build
analog@precision:~/libiio$ cd build
analog@precision:~/libiio/build$ cmake ../
analog@precision:~/libiio/build$ make
For detailed information about the different build options, see the Configuration Options section.
Install
analog@precision:~/libiio/build$ sudo make install
Note
Some things (specifically building doc) need to find libiio or the bindings on path. That means that you configure (with -DWITH_DOC=OFF), build, install, configure (with -DWITH_DOC=ON), build again to get the doc. If you have issues, please ask.
On Windows you will need to install a supported compiler such as Mingw-w64 or Visual Studio. Typically, Visual Studio will include CMake, but if you are using Mingw-w64, you will need to install it separately within the Mingw-w64 environment.
You will also need to install the following dependencies:
libxml2
libzstd
(Optional) libusb
(Optional) libserialport
These are available in the following zip for convenience.
mkdir C:\libiio-deps
cd C:\libiio-deps
Invoke-WebRequest -Uri https://swdownloads.analog.com/cse/build/libiio-deps-20220517.zip -OutFile libiio-deps-20220517.zip
Expand-Archive -Path libiio-deps-20220517.zip -DestinationPath .
Clone
C:\> mkdir dev
C:\> cd dev
C:\dev> git clone https://github.com/analogdevicesinc/libiio.git
C:\dev> cd libiio
Note
For Visual Studio, you will need to run the following command to set up the environment:
C:\> "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
This may be different depending on your version of Visual Studio. You can also use the Developer Command Prompt for Visual Studio.
Build
C:\dev\libiio> mkdir build
C:\dev\libiio> cd build
C:\dev\libiio\build> cmake -DWITH_USB_BACKEND=ON -DLIBXML2_LIBRARIES="C:\\libiio-deps\\libs\\64\\libxml2.lib" -DLIBUSB_LIBRARIES="C:\\libiio-deps\\libs\\64\\libusb-1.0.lib" -DLIBSERIALPORT_LIBRARIES="C:\\libiio-deps\\libs\\64\\libserialport.dll.a" -DLIBZSTD_LIBRARIES="C:\\libiio-deps\\libs\\64\\libzstd.dll.a" -DLIBUSB_INCLUDE_DIR="C:\\libiio-deps\\include\\libusb-1.0" -DLIBXML2_INCLUDE_DIR="C:\\libiio-deps\\include\\libxml2" -DLIBZSTD_INCLUDE_DIR="C:\\libiio-deps\\include" ..
C:\dev\libiio\build> cmake --build . --config Release
This process relies on Homebrew, a package manager for macOS. If you don’t have Homebrew installed, you can install it by running the following command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Easy: Using a homebrew formula
brew install tfcollins/libiio
Manual: Install Prerequisites
brew install cmake libxml2 libzstd libusb libserialport zstd
Optional dependencies for building documentation and python bindings:
brew install doxygen ncurses cdk sphinx-doc pkg-config
pip3 install sphinx setuptools
Clone
mkdir /tmp/dev
cd /tmp/dev
git clone https://github.com/analogdevicesinc/libiio.git
Build
cd libiio
mkdir build
cd build
cmake ..
make
Install
sudo make install
Configuration Options
when configuring libiio with cmake, there are a few optional settings that you can use to control the build. The recommendation is to leave things to the default.
Cmake Options |
Default |
Target |
Description |
|---|---|---|---|
|
ON |
All |
Build shared libraries |
|
ON |
All |
Build libiio v0.x compatibility layer |
|
OFF |
All |
Build modular backends |
‘COMPILE_WARNING_AS_ERROR’ |
OFF |
All |
Make all C warnings into errors |
|
OFF |
All |
Install C++ bindings (C++17 required for examples) |
|
OFF |
All |
Install PYTHON bindings |
|
ON |
All |
Build the utility programs (iio-utils) |
|
OFF |
All |
Build the example programs |
|
OFF |
All |
Disable multi-threading support |
|
OFF |
Windows |
Install C## bindings |
|
|
Linux |
default install path |
|
OFF |
Linux, MaC |
Create .deb/.rpm or .tar.gz packages via ‘make package’ |
|
OFF |
Linux |
Generate documentation with Doxygen and Sphinx |
|
OFF |
Linux |
Generate and install man pages |
|
ON |
Linux |
Install a Linux udev rule for detection of USB devices |
|
/lib/udev/rules.d |
Linux |
default install path for udev rules |
|
ON |
Linux |
Read local context attributes from /etc/libiio.ini |
|
ON |
Linux |
Add compatibility with the hwmon subsystem |
|
OFF |
Linux |
Build with gcov profiling flags |
|
ON |
Mac |
OS X frameworks provide the interfaces you need to write software for Mac. |
|
ON |
Mac |
Create a OSX package for installation on local and other machines |
Which backends the library supports is dependent on the build system, but can be overridden. (If cmake finds libusb, it will use it, unless turned off manually)
Cmake Options |
Default |
Depends on |
Description |
|---|---|---|---|
|
ON |
libxml2 |
Enable the XML backend, required when using network, serial, or USB backend |
|
ON |
libusb |
Enable the libusb backend |
|
ON |
Modules + USB backend |
Compile the USB backend as a module |
|
OFF |
libserialport |
Enable the Serial backend |
|
ON |
Modules + serial backend |
Compile the serial backend as a module |
|
ON |
Supports TCP/IP |
|
|
ON |
Modules + network backend |
Compile the network backend as a module |
|
OFF |
Support external backend provided by the application |
|
|
ON |
Networking |
Enable DNS-SD (ZeroConf) support |
|
ON |
Networking |
Define if you want to enable IPv6 support |
|
ON |
Linux |
Enables local support with iiod |
|
ON |
Local backend |
Read local context attributes from /etc/libiio.ini |
There are a few options, which are experimental, which should be left to their default settings:
Cmake Options |
Default |
Description |
|---|---|---|
|
ON |
Use the mmap API provided in Analog Devices’ kernel (not upstream) |
|
ON |
Use the experimental DMABUF interface (not upstream) |
|
ON |
Support for ZSTD compressed metadata |
Developer options, which either increases verbosity, or decreases size. It can be useful to keep track of things when you are developing with libiio to print out warnings, to better understand what is going on. Most users should leave it at ‘Error’ and Embedded Developers are free to set it to ‘NoLog’ to save space. this is invoked as “-DLOG_LEVEL=Debug”.
Cmake Options |
Default |
Description |
|---|---|---|
NoLog : Remove all warning/error messages |
||
|
Error : Print errors only |
|
Warning : Print warnings and errors |
||
Info |
Info : Print info, warnings and errors |
|
Debug : Print debug/info/warnings/errors (very verbose) |
Options which effect iiod only. These are only available on Linux.
Cmake Options |
Default |
Description |
|---|---|---|
|
ON |
Build the IIO Daemon |
|
ON |
Add network (TCP/IP) support |
|
ON |
Add serial (UART) support |
|
ON |
Add support for USB through FunctionFS within IIOD |
|
ON |
Add support for libiio v0.x protocol and clients |
|
OFF |
Build libtinyiiod |
|
ON |
Build IIOD with async. I/O support |
|
OFF |
Enable installation of systemd service file for iiod |
|
/lib/systemd/system |
default install path for systemd unit files |
|
OFF |
Enable installation of SysVinit script for iiod |
|
/etc/init.d |
default install path for SysVinit scripts |
|
OFF |
Enable installation of upstart config file for iiod |
|
/etc/init |
default install path for upstart conf files |
Notes
Special Note on Microsoft Visual Compiler (MSVC):
MSVC in debug mode is just very stupid. If it sees this code:
if (0)
call_function();
It will try to link against the call_function symbol even though it’s clearly dead code.
For this reason, when building with MSVC, please build in RelWithDebInfo mode. If you try to build in Debug mode, it will error.