2

I am using cmake to try to build mbedtls. I got the .zip from github, un-zipped it, then I "cd"ed into the directory of mbedtls.

I get errors like these, no matter what subdirectory/directory im in i can not build it successfully. the cmake command: cmake Visual Studio 10 .

CMake Error at CMakeLists.txt:172 (add_library):
  Cannot find source file:

    error.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx


CMake Error at CMakeLists.txt:172 (add_library):
  No SOURCES given to target: mbedcrypto

enter image description here

this is the directory i am in. All the subdirectories/cmake files are there. my question is... How can i build mbedtls on windows?

Alex Reinking
  • 16,724
  • 5
  • 52
  • 86
noah
  • 107
  • 10
  • `then I "cd"ed into the directory of mbedtls. I get errors like these` You get errors like this just from `cd` into the directory? Surely you are typing `cmake something something`. Please show what you are typing exactly. Please show full `cmake` configuration output with all messages. – KamilCuk Jul 27 '21 at 07:30
  • oh yes i forgot that, @KamilCuk – noah Jul 27 '21 at 15:50
  • Please read [this post](https://stackoverflow.com/questions/67425557/how-do-i-build-a-cmake-project) to learn how to call CMake. You should _**absolutely NEVER**_ do an in-source build with CMake. Any variation of `cmake .` is _always_ wrong. Instead you should run `cmake -G "Visual Studio 16 2019" -S . -B build` and then `cmake --build build --config Release`. (Also, are you _really_ using Visual Studio 10?! Upgrade!!) – Alex Reinking Aug 20 '21 at 22:24

2 Answers2

2

Get a release rather than a snapshot of the development branch.

Alternatively, in the 3.0+ development branch, according to the readme:

The source code of Mbed TLS includes some files that are automatically generated by scripts and whose content depends only on the Mbed TLS source, not on the platform or on the library configuration. These files are not included in the development branch of Mbed TLS, but the generated files are included in official releases. (…)

Before running cmake,

On Windows, run scripts\make_generated_files.bat to generate all the configuration-independent files.

This requires perl, python and a C compiler. You may need to set the CC environment variable to the path to cl.exe from Visual Studio.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
1

This sequence worked for me on Windows:

D:\>git clone git@github.com:ARMmbed/mbedtls.git
D:\>cd mbedtls
D:\mbedtls>scripts\make_generated_files.bat
...
D:\mbedtls>cd ..
D:\>cmake -G "Visual Studio 16 2019" -S mbedtls -B mbedtls-build
...
D:\>cmake --build mbedtls-build --config Release
...
D:\>cmake --install mbedtls-build --config Release --prefix mbedtls-install
...

The only non-standard step here is scripts\make_generated_files.bat (or /tests/scripts/check-generated-files.sh -u on Linux). One wonders why they don't include the steps to build those files as CMake custom commands... /shrug

Alex Reinking
  • 16,724
  • 5
  • 52
  • 86