Building Mbed TLS Static Libraries for Windows (MinGW & CMake) Сборка статических библиотек Mbed TLS для Windows (MinGW и CMake)

A guide to compiling Mbed TLS source code into static libraries for Windows using MinGW and CMake. Руководство по компиляции исходного кода Mbed TLS в статические библиотеки для Windows с помощью MinGW и CMake.

If you haven't set up MinGW and CMake on your machine, follow the Если вы еще не настроили MinGW и CMake на своем компьютере, следуйте инструкции: MinGW & CMake Setup Guide Руководство по настройке MinGW и CMake

Step 1: Download Mbed TLS Source Code Шаг 1: Скачивание исходного кода Mbed TLS

Download the mbedtls-x.y.z.tar.bz2 archive (do not download the generic "Source code" archive, as it lacks pre-generated generated sources) from the official GitHub releases page: Скачайте архив mbedtls-x.y.z.tar.bz2 (не скачивайте обычный архив "Source code", так как в нем отсутствуют предсгенерированные исходники) с официальной страницы релизов GitHub:

Download Mbed TLS Releases Скачать релизы Mbed TLS

Extract the downloaded archive to a convenient directory on your machine. Распакуйте скачанный архив в удобную директорию на вашем компьютере.

Step 2: Create the Build Script Шаг 2: Создание скрипта сборки

In the root directory of the extracted Mbed TLS source folder, create an empty file named build-mingw-static.bat and paste the following content into it: В корневой директории распакованного исходного кода Mbed TLS создайте пустой файл build-mingw-static.bat и вставьте в него следующее содержимое:

@echo off

if not exist build-mingw-static mkdir build-mingw-static
cd build-mingw-static

:: Clean old cache completely
if exist CMakeCache.txt del CMakeCache.txt
if exist CMakeFiles rmdir /s /q CMakeFiles

call cmake .. ^
  -DUSE_SHARED_MBEDTLS_LIBRARY=OFF ^
  -DUSE_STATIC_MBEDTLS_LIBRARY=ON ^
  -DENABLE_PROGRAMS=OFF ^
  -DENABLE_TESTING=OFF ^
  -DCMAKE_BUILD_TYPE=Release ^
  -DCMAKE_INSTALL_PREFIX=C:/libs/mbedtls-4.2.0-mingw ^
  -G "MinGW Makefiles"

call cmake --build . --config Release --parallel 8 --target install

Step 3: Run and Compile Шаг 3: Запуск и сборка

Run build-mingw-static.bat via Command Prompt (CMD) so you can catch any potential compilation errors in the console. Once completed, your compiled static libraries (such as libmbedtls.a, libmbedx509.a, libmbedcrypto.a) along with headers will be installed in the output path set by CMAKE_INSTALL_PREFIX. Запустите build-mingw-static.bat через командную строку (CMD), чтобы вы могли увидеть возможные ошибки сборки прямо в консоли. После завершения собранные статические библиотеки (такие как libmbedtls.a, libmbedx509.a, libmbedcrypto.a) вместе с заголовочными файлами будут установлены по пути, указанному в CMAKE_INSTALL_PREFIX.


Support My Work Поддержать проект

If these tutorials helped you, consider buying me a coffee! Если эти туториалы вам помогли, вы можете поддержать автора.

Sberbank (Russia only) Сбербанк (только для РФ)

Sberbank SBP QR Code

Direct transfer via phone number (Russia only) Перевод по номеру телефона (только для РФ)

+7 (917) 212-29-59

USDT TRC20

USDT TRC20 QR Code

Support via Cryptocurrency Поддержка криптовалютой

TMtY1YifNf6FKvgeFmqKGQR4NStKr3csGp