Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22016

In function __libc_init_array: undefined reference to _init

$
0
0

I'm trying to build a simple program (infinite loop) for the stm32 on the command line (Linux) and the commands used to compile and link are taken from a tutorial. I get stuck at the linking stage and I've no idea why. I guess I'm missing the _init but I'm a little suprised that it's not included in the files below. This question has been asked before here on Stackoverflow but I didn't find the suggested solutions helpful. I tried to figure out which files are needed for building programs for the stm32 and I ended up with the files below.

The files as they are named in the Cube HAL package:

cmsis_compiler.h
cmsis_gcc.h
cmsis_version.h
core_cm4.h
mpu_armv7.h
stm32l4xx.h
stm32l412xx.h
system_stm32l4xx.h
system_stm32l4xx.c
startup_stm32l412xx.S
STM32L412KBTx_FLASH.ld

I specified the microcontroller (smt32l412k8t6 in my case) by uncommenting the /*#define STM32L412xx / /!< STM32L412xx Devices */ line in stm32l4xx.h

Commands used to compile:

arm-none-eabi-gcc -x assembler-with-cpp -c -O0 -mcpu=cortex-m4 -mthumb -Wall -fmessage-length=0 startup_stm32l412xx.S -o startup_stm32l412xx.o
arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -Wall -g -fmessage-length=0 --specs=nosys.specs system_stm32l4xx.c -o system_stm32l4xx.o
arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -Wall -g -fmessage-length=0 --specs=nosys.specs  main.c -o main.o 

Command used to link + error message:

arm-none-eabi-gcc startup_stm32l412xx.o system_stm32l4xx.o main.o -mcpu=cortex-m4 -mthumb -Wall --specs=nosys.specs -nostdlib -lgcc -T./STM32L412KBTx_FLASH.ld -o main.elf

/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/thumb/v7e-m/libc.a(lib_a-init.o): In function `__libc_init_array':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/thumb/v7e-m/newlib/libc/misc/../../../../../../../newlib/libc/misc/init.c:37: undefined reference to `_init'
collect2: error: ld returned 1 exit status

Viewing all articles
Browse latest Browse all 22016

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>