PlatformIO Community

Failing to link external library

I try o link usb-pd middleware from ST, partially available as blob only:

But getting error "cannot find "

Building in release mode
arm-none-eabi-g++ -o .pio/build/hardware_gui_pd/firmware.elf -T hal/stm32g473rc_usb_pd/stm32cube/STM32G473RCTx_FLASH.ld -Os -Wl,--gc-sections,--relax -mthumb -mcpu=cortex-m4 --specs=nano.specs --specs=nosys.specs .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/app_hal.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_cortex.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma_ex.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_exti.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ex.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ramfunc.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_gpio.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c_ex.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr_ex.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc_ex.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_spi.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_spi_ex.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim_ex.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_dma.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_exti.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_gpio.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_pwr.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_tim.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_ucpd.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_utils.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Middlewares/ST/STM32_USBPD_Library/Core/src/usbpd_trace.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_cad_hw_if.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_hw.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_hw_if_it.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_phy.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_phy_hw_if.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_pwr_hw_if.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_timersserver.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/dma.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/gpio.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/i2c.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/main.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/spi.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/stm32g4xx_hal_msp.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/stm32g4xx_it.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/system_stm32g4xx.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/tim.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/ucpd.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/usbpd.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/usbpd_dpm_core.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/usbpd_dpm_user.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/usbpd_pwr_if.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/usbpd_pwr_user.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/Src/usbpd_vdm_user.o .pio/build/hardware_gui_pd/hal/stm32g473rc_usb_pd/stm32cube/startup_stm32g473xx.o .pio/build/hardware_gui_pd/src/gui/app_gui.o .pio/build/hardware_gui_pd/src/gui/fonts/my_font_roboto_14.o .pio/build/hardware_gui_pd/src/gui/fonts/my_font_roboto_16.o -L/home/vitaly/.platformio/platforms/ststm32@6.0.0/ldscripts -L.pio/build/hardware_gui_pd -Lhal/stm32g473rc_usb_pd/stm32cube/Middlewares/ST/STM32_USBPD_Library/Core/lib -Wl,--start-group .pio/build/hardware_gui_pd/lib2ed/liblvgl.a ".pio/build/hardware_gui_pd/lib0b4/libEmbedded Template Library_ID930.a" -lc -lgcc -lm -lstdc++ -lnosys -lUSBPDCORE_PD3_CONFIG_1_CM4_wc32 -Wl,--end-group
/home/vitaly/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: cannot find -lUSBPDCORE_PD3_CONFIG_1_CM4_wc32
collect2: error: ld returned 1 exit status
*** [.pio/build/hardware_gui_pd/firmware.elf] Error 1

Could you help? I’ve tried everthing i could imagine - absolute paths, -Wl,, and so on.

How to reproduce: open project from repo and try to build hardware_gui_pd target (other targets are fine).

Original Makefile, generaed by cube:

##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.7.1] date: [Tue Jun 23 19:32:02 MSK 2020] 
##########################################################################################################################

# ------------------------------------------------
# Generic Makefile (based on gcc)
#
# ChangeLog :
#	2017-02-10 - Several enhancements + project update mode
#   2015-07-22 - first version
# ------------------------------------------------

######################################
# target
######################################
TARGET = stm32cube_reflow_gui


######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization
OPT = -Og


#######################################
# paths
#######################################
# Build path
BUILD_DIR = build

######################################
# source
######################################
# C sources
C_SOURCES =  \
Src/main.c \
Src/gpio.c \
Src/dma.c \
Src/spi.c \
Src/ucpd.c \
Src/usbpd.c \
Src/usbpd_dpm_user.c \
Src/usbpd_pwr_user.c \
Src/usbpd_pwr_if.c \
Src/usbpd_dpm_core.c \
Src/stm32g4xx_it.c \
Src/stm32g4xx_hal_msp.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_utils.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_exti.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_gpio.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc_ex.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ex.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ramfunc.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_exti.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma_ex.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr_ex.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_cortex.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_spi.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_spi_ex.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim_ex.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_pwr.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_ucpd.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_gpio.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_dma.c \
Middlewares/ST/STM32_USBPD_Library/../../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_tim.c \
Src/system_stm32g4xx.c \
Middlewares/ST/STM32_USBPD_Library/Core/src/usbpd_trace.c \
Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_cad_hw_if.c \
Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_hw.c \
Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_hw_if_it.c \
Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_phy.c \
Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_phy_hw_if.c \
Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_pwr_hw_if.c \
Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_timersserver.c \
Middlewares/ST/STM32_USBPD_Library/../../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_tim.c \
Src/tim.c \
Src/i2c.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c_ex.c \
Src/usbpd_vdm_user.c

# ASM sources
ASM_SOURCES =  \
startup_stm32g473xx.s


#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
 
#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m4

# fpu
FPU = -mfpu=fpv4-sp-d16

# float-abi
FLOAT-ABI = -mfloat-abi=hard

# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)

# macros for gcc
# AS defines
AS_DEFS = 

# C defines
C_DEFS =  \
-DUSE_FULL_LL_DRIVER \
-DUSBPD_PORT_COUNT=1 \
-D_SNK \
-DUSE_HAL_DRIVER \
-DSTM32G473xx \
-DUSBPDCORE_LIB_PD3_CONFIG_1


# AS includes
AS_INCLUDES = 

# C includes
C_INCLUDES =  \
-IInc \
-IDrivers/STM32G4xx_HAL_Driver/Inc \
-IDrivers/STM32G4xx_HAL_Driver/Inc/Legacy \
-IMiddlewares/ST/STM32_USBPD_Library/Core/inc \
-IMiddlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/inc \
-IMiddlewares/ST/STM32_USBPD_Library/../../../Drivers/STM32G4xx_HAL_Driver/Inc \
-IDrivers/CMSIS/Device/ST/STM32G4xx/Include \
-IDrivers/CMSIS/Include
-IDrivers/CMSIS/Include


# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections

CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections

ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif


# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"


#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = STM32G473RCTx_FLASH.ld

# libraries
LIBS = -lc -lm -lnosys  \
-lUSBPDCORE_PD3_CONFIG_1_CM4_wc32.a
LIBDIR =  \
-LMiddlewares/ST/STM32_USBPD_Library/Core/lib
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections

# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin


#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))

$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) 
	$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@

$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
	$(AS) -c $(CFLAGS) $< -o $@

$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
	$(CC) $(OBJECTS) $(LDFLAGS) -o $@
	$(SZ) $@

$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
	$(HEX) $< $@
	
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
	$(BIN) $< $@	
	
$(BUILD_DIR):
	mkdir $@		

#######################################
# clean up
#######################################
clean:
	-rm -fR $(BUILD_DIR)
  
#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)

# *** EOF ***

Will make GCC search for a library with the name libUSBPDCORE_PD3_CONFIG_1_CM4_wc32.a. Your file is however called USBPDCORE_PD3_CONFIG_1_CM4_wc32.a, so that won’t work – renaming the file is the easiest I think.

Otherwise refer to https://stackoverflow.com/questions/1305266/how-to-link-to-a-shared-library-without-lib-prefix-in-a-different-directory and https://stackoverflow.com/a/10259822/5296568.

1 Like

@maxgerhardt Thank you very much! Since files are autogenerated by CubeMX, i had to use advice from SO.

The only strange thing is that PIO force .a drop somewhere inside, and i had o use .a.a in library name (after verbose logs inspect):

-l:USBPDCORE_PD3_CONFIG_1_CM4_wc32.a.a

That’s not critical (my build works), but seems to be a bug. Should i report it somewhere or you can forward this info properly?

Maybe PIO attempts a sort of auto-correction if it sees -l<name>.a as a common error and auto-transforms it to cut off the last two characters. Or it’s handled by SCons internally. I guess https://github.com/platformio/platformio-core is good place to ask.

1 Like

Ref: https://github.com/platformio/platformio-core/issues/3574