Nano lib doesn't build libg_s.a
I'm in project where a LPC2103 microcontroller from NXP is used. I want to use printf for debugging. But when STDIO.H was included and printf() was called the code generated became to large and doesn't fit in LPC2103 flash memory.
I found that newlib-nano shall generate libg_s.a and libc_s.a according to the README file for GNU Tools for ARM Embedded Processors Version: 5. I think that can solve my problem with the too large code.
But when i build my code with the following makefile I can't see libg_s.a or libc_s.a in my MAP file and the code is still to large.
The MAP file still show libg.a and libc.a.
I am not sure where I shall place --specs=nano.specs command in the makefile.
Please help me with this so I can continue my project and debug with printf()-function.
Regards
/Bo Liljedahl
My makefile looks like the following:
#======
# ARM makefile
#
# author: Freddie Chopin, http://
# last change: 2012-01-08
#
# this makefile is based strongly on many examples found in the network
#======
#======
# toolchain configuration
#======
TOOLCHAIN = arm-none-eabi-
CXX = $(TOOLCHAIN)g++
CC = $(TOOLCHAIN)gcc
AS = $(TOOLCHAIN)gcc -x assembler-with-cpp
OBJCOPY = $(TOOLCHAIN)objcopy
OBJDUMP = $(TOOLCHAIN)objdump
SIZE = $(TOOLCHAIN)size
RM = rm -f
#======
# project configuration
#======
# project name
PROJECT = lpc2103_blink_led
# core type
CORE = arm7tdmi-s
# linker script
LD_SCRIPT = LPC2103_rom.ld
# output folder (absolute or relative path, leave empty for in-tree compilation)
OUT_DIR = out
# C++ definitions (e.g. "-Dsymbol_
CXX_DEFS =
# C definitions
C_DEFS =
# ASM definitions
AS_DEFS =
# include directories (absolute or relative paths to additional folders with
# headers, current folder is always included)
INC_DIRS =
# library directories (absolute or relative paths to additional folders with
# libraries)
LIB_DIRS =
# libraries (additional libraries for linking, e.g. "-lm -lsome_name" to link
# math library libm.a and libsome_name.a)
LIBS =
# additional directories with source files (absolute or relative paths to
# folders with source files, current folder is always included)
SRCS_DIRS =
# extension of C++ files
CXX_EXT = cpp
# wildcard for C++ source files (all files with CXX_EXT extension found in
# current folder and SRCS_DIRS folders will be compiled and linked)
CXX_SRCS = $(wildcard $(patsubst %, %/*.$(CXX_EXT), . $(SRCS_DIRS)))
# extension of C files
C_EXT = c
# wildcard for C source files (all files with C_EXT extension found in current
# folder and SRCS_DIRS folders will be compiled and linked)
C_SRCS = $(wildcard $(patsubst %, %/*.$(C_EXT), . $(SRCS_DIRS)))
# extension of ASM files
AS_EXT = S
# wildcard for ASM source files (all files with AS_EXT extension found in
# current folder and SRCS_DIRS folders will be compiled and linked)
AS_SRCS = $(wildcard $(patsubst %, %/*.$(AS_EXT), . $(SRCS_DIRS)))
# optimization flags ("-O0" - no optimization, "-O1" - optimize, "-O2" -
# optimize even more, "-Os" - optimize for size or "-O3" - optimize yet more)
OPTIMIZATION = -Os
# set to 1 to optimize size by removing unused code and data during link phase
REMOVE_UNUSED = 1
# set to 1 to compile and link additional code required for C++
USES_CXX = 0
# define warning options here
CXX_WARNINGS = -Wall -Wextra
C_WARNINGS = -Wall -Wstrict-prototypes -Wextra
# C++ language standard ("c++98", "gnu++98" - default, "c++0x", "gnu++0x")
CXX_STD = gnu++98
# C language standard ("c89" / "iso9899:1990", "iso9899:199409",
# "c99" / "iso9899:1999", "gnu89" - default, "gnu99")
C_STD = gnu89
#======
# set the VPATH according to SRCS_DIRS
#======
VPATH = $(SRCS_DIRS)
#======
# when using output folder, append trailing slash to its name
#======
ifeq ($(strip $(OUT_DIR)), )
OUT_DIR_F =
else
OUT_DIR_F = $(strip $(OUT_DIR))/
endif
#======
# various compilation flags
#======
# core flags
CORE_FLAGS = -mcpu=$(CORE)
# flags for C++ compiler
CXX_FLAGS = -std=$(CXX_STD) -g -ggdb3 -fno-rtti -fno-exceptions -fverbose-asm -Wa,-ahlms=
# flags for C compiler
C_FLAGS = -std=$(C_STD) -g -ggdb3 -fverbose-asm -Wa,-ahlms=
# flags for assembler
AS_FLAGS = -g -ggdb3 -Wa,-amhls=
# flags for linker
LD_FLAGS = -T$(LD_SCRIPT) -g -Wl,-Map=
# process option for removing unused code
ifeq ($(REMOVE_UNUSED), 1)
LD_FLAGS += -Wl,--gc-sections
OPTIMIZATION += -ffunction-sections -fdata-sections
endif
# if __USES_CXX is defined for ASM then code for global/static constructors /
# destructors is compiled; if -nostartfiles option for linker is added then C++
# initialization / finalization code is not linked
ifeq ($(USES_CXX), 1)
AS_DEFS += -D__USES_CXX
else
LD_FLAGS += -nostartfiles
endif
#======
# do some formatting
#======
CXX_OBJS = $(addprefix $(OUT_DIR_F), $(notdir $(CXX_SRCS:
C_OBJS = $(addprefix $(OUT_DIR_F), $(notdir $(C_SRCS:
AS_OBJS = $(addprefix $(OUT_DIR_F), $(notdir $(AS_SRCS:
OBJS = $(AS_OBJS) $(C_OBJS) $(CXX_OBJS) $(USER_OBJS)
DEPS = $(OBJS:.o=.d)
INC_DIRS_F = -I. $(patsubst %, -I%, $(INC_DIRS))
LIB_DIRS_F = $(patsubst %, -L%, $(LIB_DIRS))
ELF = $(OUT_DIR_
HEX = $(OUT_DIR_
BIN = $(OUT_DIR_
LSS = $(OUT_DIR_
DMP = $(OUT_DIR_
# format final flags for tools, request dependancies for C++, C and asm
CXX_FLAGS_F = $(CORE_FLAGS) $(OPTIMIZATION) $(CXX_WARNINGS) $(CXX_FLAGS) $(CXX_DEFS) -MD -MP -MF $(OUT_DIR_
C_FLAGS_F = $(CORE_FLAGS) $(OPTIMIZATION) $(C_WARNINGS) $(C_FLAGS) $(C_DEFS) -MD -MP -MF $(OUT_DIR_
AS_FLAGS_F = $(CORE_FLAGS) $(AS_FLAGS) $(AS_DEFS) -MD -MP -MF $(OUT_DIR_
LD_FLAGS_F = $(CORE_FLAGS) $(LD_FLAGS) $(LIB_DIRS_F)
#contents of output directory
GENERATED = $(wildcard $(patsubst %, $(OUT_DIR_F)*.%, bin d dmp elf hex lss lst map o))
#======
# make all
#======
all : make_output_dir $(ELF) $(LSS) $(DMP) $(HEX) $(BIN) print_size
# make object files dependent on Makefile
$(OBJS) : Makefile
# make .elf file dependent on linker script
$(ELF) : $(LD_SCRIPT)
#------
# linking - objects -> elf
#------
$(ELF) : $(OBJS)
@echo 'Linking target: $(ELF)'
$(CXX) $(LD_FLAGS_F) $(OBJS) $(LIBS) -o $@
@echo ' '
#------
# compiling - C++ source -> objects
#------
$(OUT_DIR_F)%.o : %.$(CXX_EXT)
@echo 'Compiling file: $<'
$(CXX) -c $(CXX_FLAGS_F) $< -o $@
@echo ' '
#------
# compiling - C source -> objects
#------
$(OUT_DIR_F)%.o : %.$(C_EXT)
@echo 'Compiling file: $<'
$(CC) -c --specs=nano.specs $(C_FLAGS_F) $< -o $@
@echo ' '
#------
# assembling - ASM source -> objects
#------
$(OUT_DIR_F)%.o : %.$(AS_EXT)
@echo 'Assembling file: $<'
$(AS) -c $(AS_FLAGS_F) $< -o $@
@echo ' '
#------
# memory images - elf -> hex, elf -> bin
#------
$(HEX) : $(ELF)
@echo 'Creating IHEX image: $(HEX)'
$(OBJCOPY) -O ihex $< $@
@echo ' '
$(BIN) : $(ELF)
@echo 'Creating binary image: $(BIN)'
$(OBJCOPY) -O $< $@
@echo ' '
#------
# memory dump - elf -> dmp
#------
$(DMP) : $(ELF)
@echo 'Creating memory dump: $(DMP)'
$(OBJDUMP) -x --syms $< > $@
@echo ' '
#------
# extended listing - elf -> lss
#------
$(LSS) : $(ELF)
@echo 'Creating extended listing: $(LSS)'
$(OBJDUMP) -S $< > $@
@echo ' '
#------
# print the size of the objects and the .elf file
#------
print_size :
@echo 'Size of modules:'
$(SIZE) -B -t --common $(OBJS) $(USER_OBJS)
@echo ' '
@echo 'Size of target .elf file:'
$(SIZE) -B $(ELF)
@echo ' '
#------
# create the desired output directory
#------
make_output_dir :
$(shell mkdir $(OUT_DIR_F) 2>/dev/null)
#======
# make clean
#======
clean:
ifeq ($(strip $(OUT_DIR_F)), )
@echo 'Removing all generated output files'
else
@echo 'Removing all generated output files from output directory: $(OUT_DIR_F)'
endif
ifneq ($(strip $(GENERATED)), )
$(RM) $(GENERATED)
else
@echo 'Nothing to remove...'
endif
#======
# global exports
#======
.PHONY: all clean dependents
.SECONDARY:
# include dependancy files
-include $(DEPS)
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Bo Liljedahl
- Solved:
- Last query:
- Last reply: