This tutorial will show how to compile mbed TLS to a static
.a library file in Eclipse CDT. As it was written when mbed TLS was still called PolarSSL, it's going to use PolarSSL and polarssl for consistency between the text and the screenshots.
- Cygwin and Eclipse CDT are properly installed on the system.
If not, check our manual How to setup Eclipse CDT environment on Windows to get you started.
- You are running Eclipse on a Windows machine.
Download mbed TLS
- Go to https://tls.mbed.org/download and download the latest version of mbed TLS.
- Unpack the downloaded file to a location of your choice. (e.g.
Note: Try to avoid locations like
Documents and Settings,
Program Files (x86), etc. because spaces and special characters in your path can cause problems in Eclipse.
Create the project
- Start your Eclipse CDT environment by running eclipse.exe in the Eclipse installed directory.
- Choose an appropriate directory for your workspace (i.e., where you would like to save your project).
- You can close the ‘welcome’ screen if it shows up
- Create your new C project by choosing “File” menu ⇒ “New” ⇒ “C Project”.
- The "C Project" dialog pops up:
- In the "Project name" field, enter your project name (e.g. "polarssl") Note: Be aware that the compiler will automatically prefix your compiled static library name with ‘lib’ in front of the project name. So a project named “polarssl” will produce a libpolarssl.a library.
- Leave “Use default location” checked.
- In the "Project Types" box, select "Static Library" ⇒ "Empty Project".
- In the "Toolchains" box, choose your compiler, e.g., "Cygwin GCC" or "MinGW GCC" ⇒ Next.
- The "Select Configurations" dialog appears. Select both "Debug" and "Release" ⇒ Finish.
- Your C project is now created
Import PolarSSL code into your project
Now it is time to import all the PolarSSL code into the project and make it ready for compilation.
- Inside the Project Explorer tree on the left side, right click on your project folder and click “Properties”
- A project properties window will show up.
- Go to “C/C++ General” ⇒ “Paths and Symbols” and choose the “includes” tab.
- Under Languages, select GNU C
- Here we need to “Add…” the PolarSSL include location and hit “apply” ⇒ “ok”.
Note: Since we are dealing with a mixture of Windows/Unix based tools, we will encounter our first problem.
Option 1: Windows-style path:
If you add a Windows-style path like
C:/polarssl/include a project rebuild will fail and “make” returns an
multiple target error caused by the ‘:’-character in your path.
A solution is to always clean the project before a new rebuild.
Option 2: Cygwin-style path:
If you add a Cygwin-style path like
/cygdrive/c/polarssl/include Eclipse will warn you that the directory cannot be found and all your includes get an unresolved warning.
But the project will compile anyway.
- Right click on your project and click “Import…”
- Choose “General > Filesystem” and hit “Next”
- Browse to the PolarSSL library folder
- Select all the .c files
- Click Finish.
Build your project
Your project is now ready to be build.
- Right click on your project folder.
- Click “Build project”
- Your compiled lib .a file is located inside the Debug folder.