PlatformIO Community

Linker cannot find the object file

I’m trying to build GNUK project with PlatformIO. The original build system uses make, but I’ve decided to try to port it to PlatformIO. I’ve cloned the repository, checked out origin/STABLE-BRANCH-1-0 and created platformio.ini file. I’ve called configure --vidpid=234b:0000 in the src subfolder of the project using Git Bash command prompt. I mention all these steps so that anyone interested could reproduce the problem.

My platformio.ini file is:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]

[env]
platform = ststm32
board = bluepill_f103c8
board_build.ldscript = $PROJECT_DIR/src/gnuk.ld
board_dir = $PROJECT_DIR/boards/OLIMEX_STM32_H103a
chibi_os = $PROJECT_DIR/ChibiOS_2.0.8
cryptdir = $PROJECT_DIR/polarssl-0.14.0
cryptsrcdir = ${env.cryptdir}/library
cryptincdir = ${env.cryptdir}/include
src_filter = +<main.c> +<usb_lld.c> +<usb_desc.c> +<usb_ctrl.c> +<usb-icc.c> +<openpgp.c> +<ac.c> +<openpgp-do.c> +<flash.c> +<random.c> +<neug.c> +<sys.c> \
             +<${env.board_dir}/board.c>
             +<${env.chibi_os}/os/hal/platforms/STM32/*.c> \
             +<${env.chibi_os}/os/hal/src/*.c> \
             +<${env.chibi_os}/os/ports/GCC/ARMCMx/chcore.c> \
             +<${env.chibi_os}/os/ports/GCC/ARMCMx/chcore_v7m.c> \
             +<${env.chibi_os}/os/ports/GCC/ARMCMx/nvic.c> \
             +<${env.chibi_os}/os/ports/GCC/ARMCMx/cmsis/core_cm3.c> \
             +<${env.chibi_os}/os/kernel/src/*.c> \
             +<${env.chibi_os}/os/various/evtimer.c> \
             +<${env.chibi_os}/os/various/syscalls.c> \
             +<${env.cryptsrcdir}/bignum.c> \
             +<${env.cryptsrcdir}/rsa.c> \
             +<${env.cryptsrcdir}/aes.c> \
build_flags = -DKEYGEN_SUPPORT -I${env.cryptincdir} -I${env.chibi_os}/os/hal/include -I${env.chibi_os}/os/hal/platforms/STM32 -I${env.chibi_os}/os/ports/GCC/ARMCMx -I${env.chibi_os}/os/ports/GCC/ARMCMx/STM32F10x -I${env.chibi_os}/os/ports/GCC/ARMCMx/cmsis -I${env.chibi_os}/os/kernel/include -I$PROJECT_DIR/boards/common -I${env.board_dir} -I${env.chibi_os}/os/various

[env:OLIMEX_STM32_H103]

It’s still incomplete, but still…

The build process aborts on the linking stage:

arm-none-eabi-gcc -o .pio\build\OLIMEX_STM32_H103\firmware.elf -T "C:\Temp\Platformio Projects\gnuk/src/gnuk.ld" -Os -Wl,--gc-sections,--relax -mthumb -mcpu=cortex-m3 .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\platforms\STM32\adc_lld.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\platforms\STM32\can_lld.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\platforms\STM32\hal_lld.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\platforms\STM32\pal_lld.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\platforms\STM32\pwm_lld.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\platforms\STM32\serial_lld.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\platforms\STM32\spi_lld.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\platforms\STM32\stm32_dma.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\src\adc.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\src\can.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\src\hal.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\src\mac.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\src\mmc_spi.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\src\pal.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\src\pwm.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\src\serial.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\hal\src\spi.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chcond.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chdebug.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chevents.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chheap.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chlists.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chmboxes.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chmemcore.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chmempools.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chmsg.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chmtx.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chqueues.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chregistry.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chschd.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chsem.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chsys.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chthreads.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\kernel\src\chvt.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\ports\GCC\ARMCMx\chcore.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\ports\GCC\ARMCMx\chcore_v7m.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\ports\GCC\ARMCMx\cmsis\core_cm3.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\ports\GCC\ARMCMx\nvic.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\various\evtimer.o .pio\build\OLIMEX_STM32_H103\ChibiOS_2.0.8\os\various\syscalls.o .pio\build\OLIMEX_STM32_H103\boards\OLIMEX_STM32_H103\board.o .pio\build\OLIMEX_STM32_H103\polarssl-0.14.0\library\aes.o .pio\build\OLIMEX_STM32_H103\polarssl-0.14.0\library\bignum.o .pio\build\OLIMEX_STM32_H103\polarssl-0.14.0\library\rsa.o .pio\build\OLIMEX_STM32_H103\src\ac.o .pio\build\OLIMEX_STM32_H103\src\flash.o .pio\build\OLIMEX_STM32_H103\src\main.o .pio\build\OLIMEX_STM32_H103\src\neug.o .pio\build\OLIMEX_STM32_H103\src\openpgp-do.o .pio\build\OLIMEX_STM32_H103\src\openpgp.o .pio\build\OLIMEX_STM32_H103\src\random.o .pio\build\OLIMEX_STM32_H103\src\sys.o .pio\build\OLIMEX_STM32_H103\src\usb-icc.o .pio\build\OLIMEX_STM32_H103\src\usb_ctrl.o .pio\build\OLIMEX_STM32_H103\src\usb_desc.o .pio\build\OLIMEX_STM32_H103\src\usb_lld.o -LC:\.platformio\platforms\ststm32\ldscripts -L.pio\build\OLIMEX_STM32_H103 -Wl,--start-group -lc -lgcc -lm -lstdc++ -Wl,--end-group
c:/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find sys.o
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\OLIMEX_STM32_H103\firmware.elf] Error 1

But sys.o file is specified among the arguments to the linker, and this file is present in the build cache directory (.pio\build\OLIMEX_STM32_H103\src\sys.o). How can I fix the error?

Do you have the exact project uploaded somewhere?

I will post the link here when I manage to do it.

Done: https://github.com/me21/gnuk

Please use platformio branch.

Hmmm, if I try to issue the same command from the command line, I get the same error.
But if I remove sys.o from the command line arguments, the error stays the same! The linker complains it cannot find sys.o file. What is going on?

I’ve changed some lines in the linker script gnuk.ld, namely, the .sys section:

namely, from

    sys.o(.text)
    sys.o(.text.*)
    sys.o(.rodata)
    sys.o(.rodata.*)

to

	src\sys.o(.text)
	src\sys.o(.text.*)
    src\sys.o(.rodata)
	src\sys.o(.rodata.*)

Now I get different error:

.pio\build\OLIMEX_STM32_H103\src\sys.o:(.sys.version+0x0): multiple definition of `sys_version'
.pio\build\OLIMEX_STM32_H103\src\sys.o:(.sys.version+0x0): first defined here
.pio\build\OLIMEX_STM32_H103\src\sys.o:(.vectors+0x0): multiple definition of `vector'
.pio\build\OLIMEX_STM32_H103\src\sys.o:(.vectors+0x0): first defined here