Skip to main content
SMaci.1
Associate II
February 18, 2022
Question

Best way to add an external third party library? Is there a way to add it globally? If not, what is the best way to add a library per project? Thanks in advance!

  • February 18, 2022
  • 4 replies
  • 5872 views

I am using STM32CubeIDE version 1.8

This topic has been closed for replies.

4 replies

Nikita91
Lead II
February 18, 2022

Is it an object library or a source library?

For a source library:

  • add a new folder to your project
  • Put the sources in this folder (.c .h)
  • In the "project properties / C/C++ build / Settings / MCU GCC Compiler / include path" add a relative path to your new folder (../new_folder)

Compile the project.

To have the library common to all projects, create the folder out of the project, then create a link to this folder in every project, and add the path to the settings. https://mcuoneclipse.com/2014/08/15/link-to-files-and-folders-in-eclipse/

SMaci.1
SMaci.1Author
Associate II
February 23, 2022

Thanks for your reply and answers!

It is a source library with .c and .h files:

https://github.com/jrowberg/i2cdevlib

I guess the tricky part for me is I want to use the STM32HAL folder and within that folder some of the libraries reference other folders within that STM32HAL folder:

i.e. MPU6050 references I2Cdev.h in MPU6050.h

So I was hoping to keep the .c and .h files in their respective folders to keep everything nice and organized as I will be using a few libraries like this. Rather than having all the .c and .h files in separate folders.

Ideally organized like this:

0693W00000KaBBwQAN.png 

Rather than this kind of idea (if that is possible):

0693W00000KaBE1QAN.png 

I will look at what you sent and see if I can get it working organized in the folder structure I am hoping for!

Thanks!

SMaci.1
SMaci.1Author
Associate II
February 23, 2022

This is where I am at so far btw:

0693W00000KaBHUQA3.png 

I added the git library to the project under "Drivers" because that seemed like an appropriate place to put it. I changed 1 thing in I2Cdev to make it compatible with the board I am currently using:

#include "stm32l4xx_hal.h"

Other than that, it is all stock from the github project. I will tinker around and see if it makes sense why it is not working soon.

EDIT:

I can tell it is coming from this library reference for every folder. So I need to figure out a way to call I2Cdev from within other folders -- some sort of relative path or something

SMaci.1
SMaci.1Author
Associate II
February 23, 2022

I just figured out it was my file paths not set up which is an easy solution! This is just for this project but to do it globally you would follow the link you sent but I wanted to make sure it worked locally before trying globally since it would be great to have access to globally. Thanks again for your time and help!

0693W00000KaBNrQAN.png