cancel
Showing results for 
Search instead for 
Did you mean: 

Can't include libraries in visual code studio

Manu_30
Associate II

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

8 REPLIES 8
Manu_30
Associate II

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

Sarra.S
ST Employee

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

 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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

Sarra.S
ST Employee

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

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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.

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.
Manu_30
Associate II

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 :(

 

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

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.
Manu_30
Associate II

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...