Building own Library error

I’m having a issue when I try to build a project in the STM32Cube framework. The platform doesn’t points any error until it compiles and it doesn’t find my libraries in the main.c. All of them are already in the include path. I searched this error in the community and find it here [SOLVED] Libraries including each other lead to 'no such file or directory error' , but the solution of including “lib_ldf_mode = chain+” or “deep+” didn’t work for me.

Hi @joaopedro31451.

What compilation errors are you getting? Can you post them here as plain text please, not as screen dumps. Thanks.

I suspect that you might be compiling your main code with a file extension of “cpp” but your library file(s) have the extension “c”. If so, please rename your library files to “cpp” and it should all work.

I have a feeling that the linker is telling you that it can’t find certain functions in your library? If so, the reason is because the C++ compiler “mangles” function names to take account of the fact that functions can be overloaded in C++ but not in C.

The library functions were compiled by the C compiler which doesn’t mangle the names, but the linker is looking for the function names that the C++ compiler expects to find, and is failing because the C++ compiler didn’t compile them.

Hopefully, the error messages will see me right, but if not, we might have a better chance of helping.

Cheers,
Norm.

All of my files have the .c or .h extension. This doesn’t seen be the problem.

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F103RB.html
PLATFORM: ST STM32 (15.3.0) > STM32F103RB (20k RAM. 128k Flash)
HARDWARE: STM32F103RBT6 72MHz, 20KB RAM, 128KB Flash
DEBUG: Current (blackmagic) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES:
 - framework-stm32cubef1 @ 1.8.4
 - tool-ldscripts-ststm32 @ 0.2.0
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep+, Compatibility ~ soft
Found 29 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_adc.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_adc_ex.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_can.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_cec.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_cortex.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_crc.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_dac.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_dac_ex.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_dma.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_eth.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_exti.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_flash.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_flash_ex.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_gpio.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_gpio_ex.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_hcd.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_i2c.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_i2s.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_irda.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_iwdg.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_mmc.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_nand.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_nor.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_pccard.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_pcd.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_pcd_ex.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_pwr.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_rcc.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_rcc_ex.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_rtc.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_rtc_ex.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_sd.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_smartcard.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_spi.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_sram.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_tim.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_tim_ex.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_uart.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_usart.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_hal_wwdg.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_adc.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_crc.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_dac.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_dma.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_exti.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_fsmc.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_gpio.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_i2c.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_pwr.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_rcc.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_rtc.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_sdmmc.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_spi.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_tim.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_usart.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_usb.o
Compiling .pio\build\genericSTM32F103RB\FrameworkHALDriver\Src\stm32f1xx_ll_utils.o
Compiling .pio\build\genericSTM32F103RB\src\main.o
Compiling .pio\build\genericSTM32F103RB\src\stm32f1xx_hal_msp.o
Compiling .pio\build\genericSTM32F103RB\src\stm32f1xx_it.o
Compiling .pio\build\genericSTM32F103RB\src\syscalls.o
Compiling .pio\build\genericSTM32F103RB\src\sysmem.o
Compiling .pio\build\genericSTM32F103RB\src\system_stm32f1xx.o
src\main.c:24:10: fatal error: EasyServoControl.h: No such file or directory

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

 #include <EasyServoControl.h>
          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
*** [.pio\build\genericSTM32F103RB\src\main.o] Error 1
==================================== [FAILED] Took 8.54 seconds ====================================

I tried to change the files to .cpp just in case but the same problem occurs.

Your problem looks to be because you are not using the lib directory property.

Beneath lib you put a directory for each different library, and both the headers and c sources go in together.

So, for example you would have lib/servo containing servo.h and servo.c, lib/whatever holding whatever.h and whatever.c etc.

Your lib structure is causing the issue.

HTH

Cheers,
Norm.

It worked! Thank you!
I’m relatively new at dealing with embedded systems so i’m still learning how to structure my files and code in the best way.
Once again, thank you very much!

1 Like