Skip to main content
Visitor II
October 31, 2024
Question

Can't include libraries in visual code studio

  • October 31, 2024
  • 6 replies
  • 4199 views

Hello,

I try to do a little code for STM32F103 MCU using Visual Code Studio with STM32 VS code Extension.

I can generate and compile base code using STM32CubeMX importation feature.

But I'm stuck with adding external libraries to the project.

What i've done is to modify the "c_cpp_properties.json" file of the project to add the path to the library I want to use.

Here the current file :

 

{
 "version": 4,
 "configurations": [
 {
 /** 
 * ms-vscode.cmake-tools plugin should be installed.
 * 
 * It provides data for C/C++ plugin,
 * such as include paths, browse paths, defines, etc.
 */
 "name": "STM32",
 "includePath": [
 "lib/ssd1351"
 ],
 "configurationProvider": "ms-vscode.cmake-tools",
 //"intelliSenseMode": "${default}",
 "intelliSenseMode": "gcc-arm"
 }
 ]
}

 

 

But when I include the ssd1351.h header in the main.c file, it fail :

 

 

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "ssd1351.h"
/* USER CODE END Includes */

 

 

Can someone point me to the solution for including external libraries in an VScode project ?

Thank you

    This topic has been closed for replies.

    6 replies

    Manu_30Author
    Visitor II
    October 31, 2024

    I finally found one solution :

    I added the path to the "CMakeLists.txt" file located in "cmake" folder.

    Anyway, if there is a better/more standard way to solve the problem, I'd like to know about it.

    Thank you,

    Manu

    Visitor II
    October 12, 2025

    However, when you regenerate the project using CubeMX, any paths you added in the cmake folder will be overwritten.

    ST Employee
    October 31, 2024

    Hello @Manu_30

    Well done that's it, you need to include and link the external library ssd1351 to your CMakeLists.txt 

    • Add the include path for the ssd1351 library in target_include_directories
    • Add the ssd1351.c source file to target_link_libraries

     

     

    Manu_30Author
    Visitor II
    October 31, 2024

    Thank you Sarra.S.

    I don't understand about


    @Sarra.S wrote:
    • Add the ssd1351.c source file to target_link_libraries

     

     


    The file we speak about is this one :

    ./project_Name_Directory/cmake/stm32cubemx/CMakeLists.txt

    Correct ?

    So, in this file I wrote :

     

    target_link_directories(stm32cubemx INTERFACE
     ../../lib/ssd1351/ssd1351.c
    )

     

    Now I can use

    #include ssd1351.h

    And the code compile.

    BUT, as soon as I use a function from the librairie, I can't compile anymore. I have an error message :

    C:/Users/manu/Documents/Code/STM32F103C8T6/First/Core/Src/main.c:101: undefined reference to `SSD1351_Unselect'

    while Intellisense find the function.

    What did I miss ?

    Thank you,

    Manu

    ST Employee
    November 1, 2024

    in target_include_directories: Add the path to the ssd1351 header files

    in target sources, Add the path to the ssd1351 source files

    target_link_libraries: links the library to the project

     

    add lib.png

     check: cmake-properties(7) — CMake 3.31.0-rc3 Documentation

    Visitor II
    October 12, 2025

    Snipaste_2025-10-12_16-46-38.png

    Graduate II
    November 1, 2024

    c_cpp_properties is only for the editor so it knows where to find the header files and definitions so it can do proper syntax highlighting and suggestions.

    Manu_30Author
    Visitor II
    November 2, 2024

    Hi,

    I can't make it work :

    vscode.png

     

    Plus, I updated SMT32CubeMX to version 6.12.1 and since, STM32F103C8Tx_FLASH.ld is not correct ! It miss the RAM processors and with a straight import in VScode using STM Code extension and using "import Cmake project", the compilation fail. I have to modify the STM32F103C8Tx_FLASH.ld file per hand and add the relevant and missing section :(

     

    Graduate II
    November 2, 2024

    Are you sure "../../" is correct? That's two folders up.

    Manu_30Author
    Visitor II
    November 2, 2024

    I'm not sure, but I tried many, many possibilities without success. Even the absolute path don't operate.

    Unfortunately there is no documentation about this...