mbed TLS supports a number of different build environments out-of-the-box.

But the code and dependencies are so easy that you can build with any environment without any issues.

UNIX or Cygwin/MinGW Make

In a regular UNIX environment, or Cygwin/MinGW environment you can simply build by running:


To run the test suite, run:

make check

UNIX or Cygwin/MinGW CMake

If you have CMake, the build process is better able to handle all the dependencies and do minimal builds. To build the source using CMake, run:

cmake .

In order to run the tests, enter:

make test

The test suites need Perl to be built. If you don't have Perl installed, you'll want to disable the test suites with:


If you disabled the test suites, but kept the programs enabled, you can still run a much smaller set of tests with:


To configure CMake for building a shared library, use:


In addition the CMake build system supports different build modes, to allow the stripping of debug information, or to add coverage information to the binaries. The following modes are supported:

  • Release. This generates the default code without any unnecessary information in the binary files.
  • Debug. This generates debug information and disables optimization of the code.
  • Coverage. This generates code coverage information in addition to debug information.
  • ASan. This instruments the code with AddressSanitizer to check for memory errors. (This includes LeakSanitizer, with recent version of gcc and clang.) (With recent version of clang, this mode also intruments the code with UndefinedSanitizer to check for undefined behaviour.)
  • ASanDbg. Same as ASan but slower, with debug information and better stack traces.
  • MemSan. This intruments the code with MemorySanitizer to check for uninitialised memory reads. Experimental, needs recent clang on Linux/x86_64.
  • MemSanDbg. Same as ASan but slower, with debug information, better stack traces and origin tracking.
  • Check. This activates the compiler warnings that depend on optimisation and treats all warnings as errors.

Switching build modes in CMake is simple. For debug mode, enter at the command line:

cmake -D CMAKE_BUILD_TYPE:Debug .

To list other available CMake options, use:

cmake -LH

Note that, with CMake, if you want to change the compiler or its options after you already ran CMake, you need to clear its cache first, eg (using GNU find):

find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} +
CC=gcc CFLAGS='-fstack-protector-strong' cmake .

Windows Visual Studio 2010 and later

Inside Visual C++: open "visualc/VS2010/mbedTLS.sln" and select "Rebuild all"

If you are using a higher version of Visual Studio, it should prompt you to upgrade the files on first use - just accept and you're good to go.

Did this help?