Using my own library

Hello :slight_smile:,

I’m trying to use my own library (in local) in platformio.
This is my platformio.init:

[env:eval_f072vb]
platform = ststm32
board = eval_f072vb
framework = stm32cube
build_flags = 
    -D USE_FULL_LL_DRIVER
    -D USE_HAL_DRIVER
lib_extra_dirs =
    C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Luos
    C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Robus

I include my library “luos” in the main.c:

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "crc.h"
#include "dma.h"
#include "rtc.h"
#include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "luos.h"
/* USER CODE END Includes */ 

I use a function of this library:

/* USER CODE BEGIN 2 */
  luos_init();
  /* USER CODE END 2 */ 

This is the error i have :

Processing eval_f072vb (platform: ststm32; board: eval_f072vb; framework: stm32cube)
-----------------------------------------------------------------------------------------------------------------------------------------------------

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/eval_f072vb.html
PLATFORM: ST STM32 6.0.0 > STM32F072-EVAL
HARDWARE: STM32F072VBT6 48MHz, 16KB RAM, 128KB Flash
DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
PACKAGES:
 - framework-stm32cube 2.0.181130
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 17 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Inc>        
|   |-- <OD>     
|   |   |-- <Inc>
|   |-- <Inc>
Building in release mode
Linking .pio\build\eval_f072vb\firmware.elf
.pio\build\eval_f072vb\src\main.o: In function `main':
main.c:(.text.startup.main+0x26): undefined reference to `luos_init'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\eval_f072vb\firmware.elf] Error 1
============================================================ [FAILED] Took 2.13 seconds ============================================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

I don’t understant because VSCode recognize the function but don’t seems compile the library:

Dependency Graph
|-- <Inc>        
|   |-- <OD>     
|   |   |-- <Inc>
|   |-- <Inc>

This dependency graph looks weird. What’s the folder structure of C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Luos and C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Robus? If these are directly the library folders, you should try just adding C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev to the lib_extra_dirs and then adding

lib_deps = 
    Luos
    Robus

to the platformio.ini.

However,

Could also come from using C++ code in C in the wrong way. Are your libraries written in C++ or C?

Thank you for your quick answer :slight_smile:
My libraries are written in C.
I have a better dependencie graph by doing this in platformio.ini

[env:eval_f072vb]
platform = ststm32
board = eval_f072vb
framework = stm32cube
build_flags =
-D USE_FULL_LL_DRIVER
-D USE_HAL_DRIVER
lib_extra_dirs =
C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev
lib_deps =
Luos
Robus

But now VScode doesn’t find my library and i think it just see it like a piece of code
and not a library.

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: ST STM32 6.0.0 > STM32F072-EVAL
HARDWARE: STM32F072VBT6 48MHz, 16KB RAM, 128KB Flash
DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
PACKAGES:

  • framework-stm32cube 2.0.181130
  • toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Button\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Controlled_motor\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\DC_motor\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Distance\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Dxl\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Gate\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Gpio\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Handy\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Imu\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Led\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Led_strip\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Light_sensor\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Load\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Potentiometer\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Power_switch\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Servo\Src\syscalls.c file
    Unicode decode error has occurred, please remove invalid (non-ASCII or non-UTF8) characters from C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Boards\Stepper\Src\syscalls.c file
    Found 14 compatible libraries
    Scanning dependencies…
    Dependency Graph
    |-- < Luos>
    |–< Robus>
    Building in release mode
    Compiling .pio\build\eval_f072vb\src\adc.o
    Compiling .pio\build\eval_f072vb\src\crc.o
    Compiling .pio\build\eval_f072vb\src\dma.o
    Compiling .pio\build\eval_f072vb\src\gpio.o
    Compiling .pio\build\eval_f072vb\src\main.o
    Compiling .pio\build\eval_f072vb\src\rtc.o
    Compiling .pio\build\eval_f072vb\src\stm32f0xx_hal_msp.o
    Compiling .pio\build\eval_f072vb\src\stm32f0xx_it.o
    src\main.c:32:10: fatal error: luos.h: No such file or directory

  • Looking for luos.h dependency? Check our library registry!
  • CLI > platformio lib search “header:luos.h”
  • Web > PlatformIO Registry

#include “luos.h”
^~~~~~~~
compilation terminated.
*** [.pio\build\eval_f072vb\src\main.o] Error 1
============================================================ [FAILED] Took 3.97 seconds ============================================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

To solve that I’d have to know…

Specifically to see whether they conform to the needed default library structured explain in the README. If not, the creation of library.json is necessary which simply declares the include paths which are missing now. (an example)

C:\Users\antoi\OneDrive\Burea\LUOS\Luos_Dev\Luos Structure :
board(folder)
Inc(folder)
OD(folder)
src(folder)
.gitignore(file)
README.md(file)

C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev\Robus Structure :
doc(folder)
hal(folder)
Inc(folder)
Src(folder)
.gitignore(file)
.travis.yml(file)
README.md(file)

It seems that VSCode only see robus in libdeps.
In fact Robus depend of Luos so i tried to make this json file but nothing change:

     "name": "Luos",
     "keywords": "robus,network",
     "description": "distributing operating system",
     "version": "1.0",
     "authors": {
       "name": "Luos",
       "url": "https://luos-robotics.com"
     },
     "licence": "MIT",
     //"platforms": "espressif32",
     "build" : {
       "flags": [
         "-I Inc",
         "-I OD",
         "-I board/lo",
       ]
     },

     "dependencies":
   [
       {
           "name": "Robus",
       }
   ]

   }```

Does the project compile now and it’s just an Intellisense error? Are you getting the same error?

You put a comments in a JSON file and the JSON parser doesn’t crash on you?

Besides that the JSON file looks good, can you share a reproducable example for the project?

Hi :slight_smile:
I have the same error

* Looking for luos.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:luos.h"
* Web  > https://platformio.org/lib/search?query=header:luos.h
*
**************************************************************

 #include "luos.h"
          ^~~~~~~~
compilation terminated.
*** [.pio\build\eval_f072vb\src\main.o] Error 1 

The comment in the JSON file doesn’t make crash the JSON parser put i have the impression
that my json has no effect like my library.

This Again :sweat_smile:. If it’s reproducable I can work on it.

Also are you sure you’re putting your two library.json file in the respective folder of the library?

You should be able to see the new -I flags when you run “Verbose Compilation” (or just pio run -v). If not the library.json is malformed or in the wrong place.

Yes i made a project which reproduce the error :grinning:
How can i share it whith you ? (it’s a folder containing my library and a platformIO project)
structure of the folder:
-Driver (folder generate by cub_mx)
-Inc(folder generate by cub_mx)
-lib(folder that i create containing LUOS library)
-Project(PlatformIO project)
-Src(folder generate by cub_mx)

Normaly if you compile the platformIO project you should get this error :

> Executing task in folder Project: C:\Users\antoi\.platformio\penv\Scripts\platformio.exe run <
> 
> Processing eval_f072vb (platform: ststm32; board: eval_f072vb; framework: stm32cube)
> -----------------------------------------------------------------------------------------------------------------------------------------------------
> Verbose mode can be enabled via `-v, --verbose` option
> CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/eval_f072vb.html
> PLATFORM: ST STM32 6.0.0 > STM32F072-EVAL
> HARDWARE: STM32F072VBT6 48MHz, 16KB RAM, 128KB Flash
> DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
> PACKAGES:
>  - framework-stm32cube 2.0.181130
>  - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
> LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
> LDF Modes: Finder ~ chain, Compatibility ~ soft
> Found 7 compatible libraries
> Scanning dependencies...
> Dependency Graph
> |-- <Luos>
> Building in release mode
> Compiling .pio\build\eval_f072vb\src\adc.o
> Compiling .pio\build\eval_f072vb\src\crc.o
> Compiling .pio\build\eval_f072vb\src\dma.o
> Compiling .pio\build\eval_f072vb\src\gpio.o
> Compiling .pio\build\eval_f072vb\src\main.o
> Compiling .pio\build\eval_f072vb\src\rtc.o
> Compiling .pio\build\eval_f072vb\src\stm32f0xx_hal_msp.o
> Compiling .pio\build\eval_f072vb\src\stm32f0xx_it.o
> src\main.c:31:10: fatal error: luos.h: No such file or directory
> 
> **************************************************************
> * Looking for luos.h dependency? Check our library registry!
> *
> * CLI  > platformio lib search "header:luos.h"
> * Web  > https://platformio.org/lib/search?query=header:luos.h
> *
> **************************************************************
> 
>  #include "luos.h"
>           ^~~~~~~~
> compilation terminated.
> *** [.pio\build\eval_f072vb\src\main.o] Error 1
> ============================================================ [FAILED] Took 3.27 seconds ============================================================
> The terminal process terminated with exit code: 1
> 
> Terminal will be reused by tasks, press any key to close it.```

Either a github.com repository or a google drive / dropbox download would be appreciated

Yes of course

Here is the google drive link : Project – Google Drive