I implement a retarget.c to retarget the printf output to serial port for debugging, it can be linked and works very well, if my link command likes this:
arm-none-eabi-gcc --specs=nano.specs --specs=nosys.specs -g -mcpu=cortex-m4 -mthumb -fmessage-length=0 -std=c99 -fno-builtin -Wl,--gc-sections -Wl,-Map=main.map -T"$(LINKERFILE)" -o main.elf main.o retarget.o $(BUILDDIR)/libs.a -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group
but when I archive retarget.o
into the archive file $(BUILDDIR)/libs.a
, and the link command likes this one:
arm-none-eabi-gcc --specs=nano.specs --specs=nosys.specs -g -mcpu=cortex-m4 -mthumb -fmessage-length=0 -std=c99 -fno-builtin -Wl,--gc-sections -Wl,-Map=main.map -T"$(LINKERFILE)" -o main.elf main.o $(BUILDDIR)/libs.a -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group
it can be linked successfully, but the function printf doesn't output anything to the serial port, it seems that the my own version functions, such as _write
in the retarget.c are not used in the final compiled program.