# DeviceAtlas C API and Unix # A how-to guide to compile and run the DeviceAtlas C API on Unix systems. ### Requirements ### - A C compiler - CMake 2.6 (or above) - PCRE 6.x (or above). For best performance v8.21 (or above) is recommended or PCRE2 10.x (or above). The following compilers have been tested and are able to compile all components: - GCC (3.4 or above (4.x versions, 5.x, 7.x and onwards are recommended, the 6.x versions could possibly impact negatively the performances due to optimisations bugs)). - Clang/LLVM (3.0 or above) - Sun Pro family (12.x or above) - Intel ICC Compiler Suite (16.0 minimum recommended) - AMD CC Compiler Suite - TinyCC ### Build ### The API is compatible with ASLR with PIE enabled. #### Ubuntu/Debian #### ```shell % sudo apt-get install gcc (or clang) libpcre3-dev cmake ``` #### RedHat/CentOS #### CentOS < 8 version Note: the libzip-devel system package is obsolete, thus the libzip-last-devel ought to be used instead. A third party repository might need to be enabled. ```shell % sudo dnf install gcc (or clang) pcre-devel cmake zlib-devel libzip-last-devel \ libcurl-devel ``` CentOS >= 8 version ```shell % sudo dnf install gcc (or clang) pcre-devel cmake zlib-devel libzip-devel \ libcurl-devel ``` #### MacOS #### ```shell % brew install gcc (or clang ; not necessary if clang from XCode is already installed) pcre cmake zlib libzip curl ``` #### FreeBSD ### ```shell % sudo pkg install pcre cmake zlib libzip libcurl openssl or openssl-devel (openssl recommended) (optional) % sudo pkg install gcc<any version> (or llvm<any version>) if another compiler different from the base system is preferred ``` #### Compiling the API #### ```shell % cd <path to the extracted api archive> % cmake . % make ``` ### Optional ### - CURL - OpenSSL or LibreSSL - libzip (1.x versions). - zlib Note: Some operating systems allow to install several versions of CURL with different backends (OpenSSL, NSS, GNUTls), while the API will attempt to check the library consistency, it is advised to install one backend at a time if possible. In other situations and if an issue happens at request time, it is possible to reorder the libraries loading with LD_PRELOAD=<path to the CURL library>. ### CMake ### By default CMake should find all necessary components if they are installed with a package manager. This section describes setting cmake variables to handle components installed in custom locations. ** PCRE/PCRE2 library and headers ** If the PCRE/PCRE2 library and headers are located in a custom location, the following cmake environment variables may be set: - REGEXLIBS=&lt;path to the pcre/pcre2 library&gt; - REGEX_INCLUDE_DIR=&lt;path to the pcre/pcre2 headers folder&gt; (For Red Hat based operating systems, the required packages are pcre-devel/pcre2-devel; for Debian, the names are libpcre3-dev/libpcre2-dev (the 8 wide character support at least needs to be present); otherwise, please check pcre/pcre2 and zlib development packages with your package manager). For example (pcre): ```shell cmake -DREGEXLIBS=/home/test/pcre/lib/libpcre.so -DREGEX_INCLUDE_DIR=/home/test/pcre/include ``` For example (pcre2): ```shell cmake -DREGEXLIBS=/home/test/pcre2/lib/libpcre2-8.so -DREGEX_INCLUDE_DIR=/home/test/pcre2/include -DREGEX_ENGINE=pcre2 ``` Compatibility: For older PCRE versions it is possible to disable the PCRE Study feature with cmake -DPCRE_STUDY=0. It is highly recommended to NOT disable PCRE Study for better performance. For PCRE, JIT support can be checked simply with the pcre2test utility ```shell % pcretest -C jit % 1 ``` For PCRE2, JIT support can be checked simply with the pcre2test utility ```shell % pcre2test -C jit % 1 ``` ** Custom compiler location ** - CMAKE_C_COMPILER=&lt;full path to the C compiler executable&gt; For example: ```shell cmake -DCMAKE_C_COMPILER=/home/test/gcc-4.8.3/bin/gcc -DCMAKE_CXX_COMPILER=/home/test/gcc-4.8.3/bin/g++ ``` NB: For a static API version used with another shared library it is possible to use CFLAGS/CXXFLAGS with -fPIC/fpic compilation flag. ### Install the API (Optional) ### ```shell % cd <path to the extracted api archive> % sudo make install % sudo ldconfig ``` (Optional) It is possible to build the API with shortened shlib values. ```shell % cmake -DSHORT_VERSION=ON (OFF by default) % make ``` It is possible to set the regex engine backend. ``` (pcre) % cmake . (or pcre2) % cmake -DREGEX_ENGINE=pcre2 % make ``` ### Sample applications ### There are multiple examples in the /Examples folder to test the API. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _ Copyright (c) DeviceAtlas Limited 2021. All Rights Reserved. _ https://deviceatlas.com <!-- HTML+JS for document formatting when opened in browser --> <div class="btn-group" id="main-menu" style="float:right"><a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Menu<span class="caret"></span></a><ul class="dropdown-menu"><li><a href="README.html">Main</a></li><li class="divider"></li><li><a href="README.DeviceApi-Web.html">Device Detection for Web</a></li><li><a href="README.DeviceApi-Apps.html">Device Detection for Apps</a></li><li><a href="README.DeviceApi-Config.html">Device Detection API Config</a></li><li><a href="README.CarrierApi.html">Carrier Identification API</a></li><li class="divider"></li><li class="disabled"><a href="README.Unix.html">C API and Unix</a></li><li><a href="README.Windows.html">C API and Windows</a></li><li class="divider"></li><li><a href="README.Nginx.html">C API and NGINX Module Installation</a></li><li class="divider"></li><li><a href="README.JsonConverter.html">C API JSONConverter</a></li><li><a href="https://docs.deviceatlas.com/apis/clientside/latest/README.ClientSide.html" target="_blank">Client-side Component</a></li><li><a href="README.ConnectivityAnalyser-Nginx.html">NGINX DeviceAtlas Connectivity Analyser</a></li><li><a href="README.ConnectivityAnalyser-Apache.html">Apache DeviceAtlas Connectivity Analyser</a></li><li><a href="ApiDocs/index.html">DeviceAtlas ApiDocs</a></li></ul></div>