Since different files are compiled for different CPU classes, and to prevent unwanted optimizations, link-time optimization (LTO) should not be used.
Also, do not enable sanitizers (such as -fsanitize=signed-integer-overflow). These can introduce side channels.
On Linux, if the process hangs at the make check step, your system PRG may not have been properly seeded. Please refer to the notes in the “Usage” section for ways to address this.
Also, on Linux, like any manually installed library, running the ldconfig command is required to make the dynamic linker aware of the new library.
Compilation on Windows
Compilation on Windows is usually not required, as pre-built libraries for MinGW and Visual Studio are available (see below).
However, if you want to compile it yourself, start by cloning the stable branch from the Git repository.
Visual Studio solutions can be then found in the builds/msvc directory.
In order to compile with MinGW, run either ./dist-build/msys2-win32.sh or ./dist-build/msys2-win64.sh for Win32 or x64 targets.
Alternatively, you can build and install libsodium using vcpkg dependency manager:
The libsodium port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.
Pre-built libraries
Pre-built x86 and x86_64 libraries for Visual Studio 2017, 2019, and 2022 with stable additions (see below) are available, as well as pre-built libraries for MinGW32 and MinGW64. Note that pre-built libraries are built with the run-time Multi-threaded (/MT) and not with Multi-threaded DLL (/MD).
They include header files as well as static (.LIB) and shared (.DLL) libraries for all the supported compiler versions.
Note for Visual Studio
Projects willing to statically link Sodium must define a macro named SODIUM_STATIC. This will prevent symbol definitions from being referenced with __dllexport.
Cross-compiling to Android
After unpacking the source distribution (stable is recommended), set ANDROID_NDK_HOME to the path to the Android SDK. Note that compilation is only tested on CI with the LTS version of the SDK.
Then, run the android-aar.sh script:
./dist-build/android-aar.sh
This will compile libsodium (full builds and minimal builds) for every Android architectures. The resulting libraries are in libsodium-android-<architecture> folders.
In addition, this creates AAR files, that can be directly included in projects using gradle or cmake. After compilation, the script outputs the instructions to do so.
Cross-compiling to Apple devices
The apple-xcframework.sh scripts crates an xcframework package containing libsodium for iOS, macOS, Catalyst, watchOS, tvOS, visionOS and their respective emulators:
./dist-build/apple-xcframework.sh
Cross-compiling to ARM microcontrollers
Here is an example of cross-compiling to ARM using the GNU tools for ARM embedded processors:
We recommend using distribution tarballs over cloning the libsodium Git repository, especially since tarballs do not require dependencies, such as Libtool and Autotools.
However, if cloning a Git repository happens to be more convenient, the stable branch always contains the latest stable release of libsodium, plus minor patches that will be part of the next version and critical security fixes while new packages including them are being prepared.
Code in the stable branch also includes generated files, and does not require the autotools (Libtool, Autoconf, and Automake) to be present.
We encourage users and researchers to use PGP encrypted emails to transmit confidential details regarding possible vulnerabilities in the Sodium library.
Details should be sent to j [at] pureftpd [dot] org using the PGP key above.