| 分享SDCC\IAR下.lib生成与使用经验1. IAR下生成.lib
 
 只需要修改如图选项即可。菜单-》Project-》Make 
 2. IAR下使用.lib和keil操作一致,直接添加进工程即可 
 3 SDCC生成.lib调用 sdar生成.lib Usage: sdar [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV] [--plugin <name>] [member-name] [count] archive-file file...
       sdar -M [<mri-script]
 commands:
  d            - delete file(s) from the archive
  m[ab]        - move file(s) in the archive
  p            - print file(s) found in the archive
  q[f]         - quick append file(s) to the archive
  r[ab][f][u]  - replace existing or insert new file(s) into the archive
  s            - act as ranlib
  t[O][v]      - display contents of the archive
  x[o]         - extract file(s) from the archive
 command specific modifiers:
  [a]          - put file(s) after [member-name]
  [b]          - put file(s) before [member-name] (same as [i])
  [D]          - use zero for timestamps and uids/gids
  [U]          - use actual timestamps and uids/gids (default)
  [N]          - use instance [count] of name
  [f]          - truncate inserted file names
  [P]          - use full path names when matching
  [o]          - preserve original dates
  [O]          - display offsets of files in the archive
  [u]          - only replace files that are newer than current archive contents
 generic modifiers:
  [c]          - do not warn if the library had to be created
  [s]          - create an archive index (cf. ranlib)
  [l <text> ]  - specify the dependencies of this library
  [S]          - do not build a symbol table
  [T]          - deprecated, use --thin instead
  [v]          - be verbose
  [V]          - display the version number
  @<file>      - read options from <file>
  --target=BFDNAME - specify the target object format as BFDNAME
  --output=DIRNAME - specify the output directory for extraction operations
  --record-libdeps=<text> - specify the dependencies of this library
  --thin       - make a thin archive
 optional:
  --plugin <p> - load the specified plugin
 emulation options:
  No emulation specific options
sdar: supported targets: asxxxx srec symbolsrec verilog tekhex binary ihex plugin
 Makefile如下: ROOT_DIR := ../
TARGET = add
BUILD_DIR =  ./build/
#obj2占位符抵消../
BUILD_OBJ_DIR =  ./build/obj/obj2/
PREFIX = 
CC = $(PREFIX)sdcc 
AS = $(PREFIX)sdas8051 #sdc51
RM = -rm -rf
MAKE = make 
MCU_MODEL = -mmcs51
MODEL  = --model-large
CODE_SIZE = --code-size 65536  # 64KB 的 Flash 存储器
IRAM_SIZE = --iram-size 2048    # 2KB 的内部 SRAM
XRAM_SIZE = --xram-size 32768   # 32KB 的内部扩展 RAM
AS_DEFS = 
C_DEFS = 
# includes,头文件必须包含在以下文件中
AS_INCLUDES = 
INC_PATHS =  \
-I$(ROOT_DIR)App \
-I$(ROOT_DIR)User \
-I$(ROOT_DIR)inc
# libraries
USER_SRC =  $(ROOT_DIR)Library
C_SOURCES := $(USER_SRC)/add.c
 # 对象文件
C_OBJECTS := $(patsubst %.c, $(BUILD_OBJ_DIR)/%.rel, $(C_SOURCES))
# 最终目标文件
ALL_OBJECTS := $(C_OBJECTS) 
# 规则
.PHONY: all clean mk
# 主要目标
all: $(BUILD_DIR)/$(TARGET).lib
# 清理
clean:
    -rm -rf $(BUILD_DIR)/*
# 编译
$(BUILD_OBJ_DIR)/%.rel: %.c
    @echo "Compiling $< into $(dir $@)"
    mkdir -p $(dir $@) | $(CC) -c -o $@ $(MCU_MODEL) $(INC_PATHS) $(MODEL) --out-fmt-ihx --debug $<
# 链接生成
$(BUILD_DIR)/$(TARGET).lib: $(ALL_OBJECTS)
    @echo "Compiling $^ into $(dir $@)"
    mkdir -p $(dir $@) | sdar rv $@ $^
# 删除构建目录
clean-build-dir:
    rm -rf $(BUILD_DIR)
 4 SDCC使用.lib通过 LDFLAGS调用lib,-L包含lib库目录,-l链接指定lib Makefile语法如下: ROOT_DIR := ../
TARGET = downloadfile
BUILD_DIR =  ./build/
#obj2占位符抵消../
BUILD_OBJ_DIR =  ./build/obj/obj2/
PREFIX = 
CC = $(PREFIX)sdcc 
AS = $(PREFIX)sdas8051 #sdc51
RM = -rm -rf
MAKE = make 
MCU_MODEL = -mmcs51
MODEL  = --model-large
CODE_SIZE = --code-size 65536  # 64KB 的 Flash 存储器
IRAM_SIZE = --iram-size 2048    # 2KB 的内部 SRAM
XRAM_SIZE = --xram-size 32768   # 32KB 的内部扩展 RAM
AS_DEFS = 
C_DEFS = 
# includes,头文件必须包含在以下文件中
AS_INCLUDES = 
INC_PATHS =  \
-I$(ROOT_DIR)Driver/inc \
-I$(ROOT_DIR)User \
-I$(ROOT_DIR)Library
# libraries
LIBS = -ladd
LIBDIRS = -L../SDCC-lib/build
LIB_SRC = 
USER_SRC =  $(ROOT_DIR)User
C_SOURCES := $(wildcard   $(ROOT_DIR)Driver/src/*.c  $(ROOT_DIR)Driver/isr/*.c    $(ROOT_DIR)App/src/*.c)
C_SOURCES += $(USER_SRC)/Main.c
ASM_SOURCES = 
 # 对象文件
C_OBJECTS := $(patsubst %.c, $(BUILD_OBJ_DIR)/%.rel, $(C_SOURCES))
ASM_OBJECTS := $(patsubst %.asm, $(BUILD_OBJ_DIR)/%.rel, $(ASM_SOURCES))
# 最终目标文件
ALL_OBJECTS := $(C_OBJECTS) $(ASM_OBJECTS)
# 链接选项
LDFLAGS =  $(LIBDIRS) $(LIBS) # 删除未使用的段
# 规则
.PHONY: all clean mk
# 主要目标
all: $(BUILD_DIR)/$(TARGET).hex
# 清理
clean:
    -rm -rf $(BUILD_DIR)/*
# 编译规则
$(BUILD_OBJ_DIR)/%.rel: %.c
    @echo "Compiling $< into $(dir $@)"
    mkdir -p $(dir $@) | $(CC) -c -o $@ $(MCU_MODEL) $(INC_PATHS) $(MODEL) --out-fmt-ihx --debug $<
$(BUILD_OBJ_DIR)/%.rel: %.asm
    @echo "Compiling $< into $(dir $@)"
    mkdir -p $(dir $@) | $(AS) -o $(INC_PATHS) $@ $<
# 链接规则
$(BUILD_DIR)/$(TARGET).hex: $(ALL_OBJECTS)
    @echo "Compiling $^ into $(dir $@)"
    mkdir -p $(dir $@) | $(CC) -o $@ $(MCU_MODEL) $(INC_PATHS) $(MODEL) $(CODE_SIZE) $(IRAM_SIZE) $(XRAM_SIZE) $(LDFLAGS) --out-fmt-ihx $^
# 删除构建目录
clean-build-dir:
    rm -rf $(BUILD_DIR)
 5. 工程文件 附件:Project.zip
 |