默认情况下vscode并不能支持sdcc的扩展语法,但是可以配置简单忽略这些对语义没有影响的扩展关键词。
在打开的目录下新建: .vscode/c_cpp_properties.json
- {
- "configurations": [
- {
- "name": "sdcc",
- "compilerPath": "/usr/bin/sdcc",
- "intelliSenseMode": "linux-gcc-x64",
- "cStandard": "c23",
- "cppStandard": "gnu++17",
- "defines": [
- "__sfr=unsigned char",
- "__sbit=int",
- "__at(a)= ",
- "__data= ",
- "__xdata= ",
- "__interrupt n= ",
- "__using= "
- ]
- }
- ],
- "version": 4
- }
复制代码
这样默认的C/C++插件就不会报错了。
假定目录结构:
-/
-bin
-src
-inc
入口在src/main.c
简单编写一个makefile:
- # Makefile template for stc8h projects using SDCC
-
- # Compiler and linker flags
- CFLAGS = -mmcs51 --std-sdcc2x --model-large --opt-code-speed \
- --code-size 0xffff --xram-size 0x2000
-
- # Define the compiler and the linker
- # CC = sdcc
- CC := $(if $(shell echo $$SDCC_PATH),$(shell echo $$SDCC_PATH),sdcc)
-
- # Define the project directories
- SRCDIR = src
- INCDIR = inc
- BINDIR = bin
-
- # Define the target name
- TARGET = $(BINDIR)/main.ihx
- ENTRY = main.c
-
- # Define the C source and header files
- SRC := $(filter-out $(SRCDIR)/$(ENTRY), $(wildcard $(SRCDIR)/*.c))
- OBJ = $(SRC:$(SRCDIR)/%.c=$(BINDIR)/%.rel)
- INC = -I$(INCDIR)
-
- # Define the phony targets
- .PHONY: all clean
-
- # Default target
- all: $(TARGET)
-
- # Link the object files into the final binary
- $(TARGET): $(OBJ) $(SRCDIR)/$(ENTRY)
- $(CC) $(CFLAGS) $(INC) -o $(TARGET) $^
- @cat $(BINDIR)/main.mem
-
- # Compile the source files into object files
- $(BINDIR)/%.rel: $(SRCDIR)/%.c
- @mkdir -p $(@D)
- $(CC) $(CFLAGS) $(INC) -c $< -o $@
-
- # Clean up the build files
- clean:
- rm -f ./$(BINDIR)/*
复制代码
用 make clean && make 就能完成大部分开发了。
|