cancel
Showing results for 
Search instead for 
Did you mean: 

How to add Eigen library C++ to STM32CUBEIDE

Bachir
Associate

Hi, 

I need help with instructions how I add the Eigen library C++ library to an STM32CUBE IDE project. I have created a project with no target for simplicity, using C++ as the basis language. I have downloaded the open source Eigen C++ library which supports matrix calculations. But I am having difficulties how to add it to the STM32 project. 

Can someone who has used this library with STM32 Cube, help with instructions how I can add it please ? 

1 - I created a foder lib under my project explorer, and copied the Eigen library to this folder (as shown in the attached picture pic1)

2 - I added the path to eigen lib in both the includes and source locations in the paths and symbols. (pic2)

When I build the main.cpp as it is first, I get a lot of errors. 

Can Anybody help by giving instructions how i add this library? 

 

I am attaching my project to this post too.

 

 

6 REPLIES 6
Rim LANDOLSI
ST Employee

Hello @Bachir  and welcome to the community,

This knowledge base article may help you link an external library to the STM32CubeIDE project.

Hope this helps you!

Thanks,
Rim.

mikewhooo
Associate II

I hope this message finds you well. I wanted to follow up and ask if you were able to resolve the issue you mentioned regarding the Eigen library. I am encountering the same problem, where it keeps showing an error about a missing main.h file.

Any help or insights you could provide would be greatly appreciated!

Looks like you include some test programs into the library and these programs have their own main. You don't want these test modules in the library.

 

Hello, 

Yes I did solve the problem. In brief, you need to add the Eigen library to the stm32 project you are working on. One issue I encountered is that you need to disable some of the memory deallocation checks built in stm32, because somehow when you create a matrix using C++ class, the stm32 does not recognise the destructor implicitly called in the matrix generation. 

If you can be patient this week I can search for an example that worked for me and post it here. 

Just a side note, there are also other libraries out there you can search for that implement matrix operations and linear algebra and are built in C.  

- Bachir

Thank you all very much! After some attempts, I found that simply placing the **Eigen** folder from the downloaded files into my project resolved the issue. Now, using Eigen no longer causes any difficulties, and the code compiles without syntax errors. However, my project's main files are written in C, with only one file, **kalman.cpp**, written in C++. When attempting to perform C/C++ mixed programming, I always encounter errors saying `<vector>` cannot be found. Additionally, I have a static library file ending with **.a**, which also fails to link. Could anyone advise on the correct steps for implementing C/C++ mixed programming?
I would be immensely grateful.

mikewhooo
Associate II

Thank you all, I have resolved the C/C++ programming issue. To use Eigen, simply copy the Eigen folder into your project and include `<Eigen>` to use it. When creating a new `.cpp` file, you need to rename `main.c` to `main.cpp`, and all other `.c` files you wrote should also be renamed to `.cpp`.