I changed it into a three step process.
# 1. Make build/libch.a
Code: Select all
>> make lib (without main.c)
(last few line of the output)
arm-none-eabi-ar -r build/libch.a build/obj/crt0_v7m.o build/obj/chcoreasm_v7m.o build/obj/crt1.o build/obj/vectors.o build/obj/chsys.o build/obj/chdebug.o build/obj/chvt.o build/obj/chschd.o build/obj/chthreads.o build/obj/chtm.o build/obj/chdynamic.o build/obj/chregistry.o build/obj/chsem.o build/obj/chmtx.o build/obj/chcond.o build/obj/chevents.o build/obj/chmsg.o build/obj/chmboxes.o build/obj/chqueues.o build/obj/chmemcore.o build/obj/chheap.o build/obj/chmempools.o build/obj/chcore.o build/obj/chcore_v7m.o build/obj/osal.o build/obj/hal.o build/obj/st.o build/obj/hal_queues.o build/obj/hal_mmcsd.o build/obj/pal.o build/obj/serial.o build/obj/usb.o build/obj/nvic.o build/obj/stm32_dma.o build/obj/hal_lld.o build/obj/st_lld.o build/obj/pal_lld.o build/obj/usb_lld.o build/obj/serial_lld.o build/obj/board.o build/obj/test.o build/obj/testthd.o build/obj/testsem.o build/obj/testmtx.o build/obj/testmsg.o build/obj/testmbox.o build/obj/testevt.o build/obj/testheap.o build/obj/testpools.o build/obj/testdyn.o build/obj/testqueues.o build/obj/testsys.o build/obj/testbmk.o
arm-none-eabi-ar: creating build/libch.a
Done
# 2. compile main.c
Code: Select all
>> arm-none-eabi-gcc -c -mcpu=cortex-m4 -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -ffunction-sections -fdata-sections -fno-common -flto -Wall -Wextra -Wstrict-prototypes -Wa,-alms=build/lst/testbmk.lst -DCORTEX_USE_FPU=FALSE -DTHUMB_PRESENT -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -MD -MP -MF .dep/testbmk.o.d -mthumb -DTHUMB -I. -I../../../os/common/ports/ARMCMx/devices/STM32F4xx -I../../../os/ext/CMSIS/include -I../../../os/ext/CMSIS/ST -I../../../os/rt/include -I../../../os/rt/ports/ARMCMx -I../../../os/rt/ports/ARMCMx/compilers/GCC -I../../../os/hal/osal/rt -I../../../os/hal/include -I../../../os/hal/ports/common/ARMCMx -I../../../os/hal/ports/STM32/STM32F4xx -I../../../os/hal/ports/STM32/LLD -I../../../os/hal/ports/STM32/LLD/DACv1 -I../../../os/hal/ports/STM32/LLD/GPIOv2 -I../../../os/hal/ports/STM32/LLD/I2Cv1 -I../../../os/hal/ports/STM32/LLD/OTGv1 -I../../../os/hal/ports/STM32/LLD/RTCv2 -I../../../os/hal/ports/STM32/LLD/SPIv1 -I../../../os/hal/ports/STM32/LLD/TIMv1 -I../../../os/hal/ports/STM32/LLD/USARTv1 -I../../../os/hal/ports/STM32/LLD/FSMCv1 -I../../../os/hal/boards/ST_STM32F4_DISCOVERY -I../../../test/rt -I../../../os/various main.c -o build/obj/main.o
# 3. Link main.o and libch.a to create ch.elf
Code: Select all
>> arm-none-eabi-gcc build/libch.a build/obj/main.o -mcpu=cortex-m4 -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -ffunction-sections -fdata-sections -fno-common -flto -nostartfiles -Wl,-Map=build/ch.map,--cref,--no-warn-mismatch,--library-path=../../../os/common/ports/ARMCMx/compilers/GCC,--script=../../../os/common/ports/ARMCMx/compilers/GCC/ld/STM32F407xG.ld,--gc-sections,--defsym=__process_stack_size__=0x400,--defsym=__main_stack_size__=0x400 -mno-thumb-interwork -mthumb -o build/ch.elf
build/libch.a(crt0_v7m.o): In function `Reset_Handler':
(.text+0x12): undefined reference to `__early_init'
build/libch.a(crt0_v7m.o): In function `bloop':
(.text+0x58): undefined reference to `__late_init'
build/libch.a(crt0_v7m.o): In function `endfiniloop':
(.text+0x80): undefined reference to `__default_exit'
/tmp/cc3N0kYO.ltrans0.ltrans.o: In function `Thread1':
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:32: undefined reference to `chThdSleep'
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:34: undefined reference to `chThdSleep'
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:34: undefined reference to `ch'
/tmp/cc3N0kYO.ltrans0.ltrans.o: In function `main':
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:50: undefined reference to `halInit'
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:51: undefined reference to `chSysInit'
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:57: undefined reference to `sdStart'
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:58: undefined reference to `_pal_lld_setgroupmode'
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:59: undefined reference to `_pal_lld_setgroupmode'
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:64: undefined reference to `chThdCreateStatic'
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:73: undefined reference to `chThdSleep'
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:72: undefined reference to `TestThread'
/home/jayram/Project/chibi_stm/ext/chibios/demos/STM32/RT-STM32F407-DISCOVERY/main.c:72: undefined reference to `SD2'
collect2: error: ld returned 1 exit status
I am not sure why the link failed when I did by the second way.
Any help will be appreciated.