🔷 How to properly add library to your STM32CubeIDE project? SOLUTION INSTRUCTIONS.
Introduction
STM32CubeIDE based on Eclipse IDE, it's powerful and slow, but it works and pretty good for coding. But you may run into problems when adding the custom libraries:
- CubeIDE cannot find header files after import ❓
- STM32CubeIDE not including library files correctly ❓
So, this article will tell you how to correctly adding of libraries ?
Choose library and prepare files
I think you already have library files, that you want. Typically this files located at the hosting service with version control system (git) or just server or cloud drive...
For example, here you can see my library for internal temperature sensor of STM32 (➡️ https://github.com/Egoruch/Internal-Temperature-Sensor-STM32-HAL snapshot from 06/01/2023 ), for download it press green button Code-> Download ZIP:
In fact, it's full project, which is more useful for most of embedders, because you can find out configuration of MCU in Cube. So .c and .h files located it Core/Src and Core/Inc folders (but I strongly not recommend do like this, place library in separate folder, because it can be deleted by Cube ?). So I download full repository and extract files:
- tmpsensor.c
- tmpsensor.h
Usually simple library have two files (source.c and include.h), but there may be more (files with constants, configurations, auxiliary, drivers, GUI...).
Copy library files to project
You can do this by copying and paste files into project folder directly in system Explorer (or with Project Explorer in STM32CubeIDE window). Then righ-click on project name and press Refresh (new files should (new files should be displayed).
Try to include library
Include library header file:
Try to build project (right-click on the project name -> Build Project) – Error ?.. We exactly know, that tmpsensor.h file exist in the project directory, but STM32CubeIDE (Eclipse) doesn't see it.
- Build Failed. 3 errors, 0 warning
- fatal error: tmpsensor.h: No such file or directory
⏩ Solve
We need to specify location paths to .h AND .c files for project, so open project Properties (right click on project name -> Properties, before it make active any file from project).
In Properties for *Project Name* window:C/C++ General -> Paths and Symbols -> Includes -> Add… -> Type *path to folder*-> OK
Now .h files in this folders will be known for IDE, check again destination:
In Properties for*Project Name*window:C/C++ General -> Paths and Symbols -> Source Location -> Add Folder… -> Choose folder-> OK -> Apply and Close
Update 07/29/2023: Note: if you don't see you project's folder close this window and press Project -> Build Project and then try again to add Src file.
Now .c files in this folders will be known for IDE, check again destination:
Try to build project again (right-click on the project name -> Build Project), it's good even when we use functions of the library:
Conclusions
Paths to library files (.c and .h) should be specified in project properties manually ?.
THIS INSTRUCTION DOES'T USE git submodule TO SIMPLIFIED STEPS TO ACHIEVE RESULT. ANOTHER INSTRUCTION WILL BE DISCLOSURE USING git submodule TO MAKE COPYING AND UPDATING OF LIBRARY FILES MORE CONVINIENT AND RELIABLE.
- 1 comment