1看看书《跟我一起写Makefile》
CROSS_COMPILE ?= arm-linux-gnueabihf-
TARGET ?= lcd
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
OBJCOPY := $(CROSS_COMPILE)objcopy
OBJDUMP := $(CROSS_COMPILE)objdump
LIBPATH := -lgcc -L /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/4.9.4
INCDIRS := imx6ul \
stdio/include \
bsp/clk \
bsp/led \
bsp/delay \
bsp/beep \
bsp/gpio \
bsp/key \
bsp/exit \
bsp/int \
bsp/epittimer \
bsp/keyfilter \
bsp/uart \
bsp/lcd
SRCDIRS := project \
stdio/lib \
bsp/clk \
bsp/led \
bsp/delay \
bsp/beep \
bsp/gpio \
bsp/key \
bsp/exit \
bsp/int \
bsp/epittimer \
bsp/keyfilter \
bsp/uart \
bsp/lcd
INCLUDE := $(patsubst %, -I %, $(INCDIRS))
SFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.S))
CFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c))
SFILENDIR := $(notdir $(SFILES))
CFILENDIR := $(notdir $(CFILES))
SOBJS := $(patsubst %, obj/%, $(SFILENDIR:.S=.o))
COBJS := $(patsubst %, obj/%, $(CFILENDIR:.c=.o))
OBJS := $(SOBJS) $(COBJS)
VPATH := $(SRCDIRS)
.PHONY: clean
$(TARGET).bin : $(OBJS)
$(LD) -Timx6ul.lds -o $(TARGET).elf $^ $(LIBPATH)
$(OBJCOPY) -O binary -S $(TARGET).elf $@
$(OBJDUMP) -D -m arm $(TARGET).elf > $(TARGET).dis
$(SOBJS) : obj/%.o : %.S
$(CC) -Wall -nostdlib -fno-builtin -c -O2 $(INCLUDE) -o $@ $<
$(COBJS) : obj/%.o : %.c
$(CC) -Wall -Wa,-mimplicit-it=thumb -nostdlib -fno-builtin -c -O2 $(INCLUDE) -o $@ $<
clean:
rm -rf $(TARGET).elf $(TARGET).dis $(TARGET).bin $(COBJS) $(SOBJS)
2
(1)
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
(2)
{
//用户自定义变量,可用于在其他配置属性中进行替换,在本例中myDefaultIncludePath即为用户自定义变量,在configurations.includePath字段下被引用。
"env": {
"myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
"myCompilerPath": "/usr/local/bin/gcc-7"
},
//一组配置对象,向智能感知引擎提供有关你的项目和首选项的信息。默认情况下,扩展插件会根据操作系统自动创建相关信息,我们自定义配置主要就是修改这里。
"configurations": [
{
"name": "Mac",/*用来标识配置文件,一般是内核的名字就可以了,如"Linux"*/
"intelliSenseMode": "clang-x64",/*智能感知模式,有msvc-x64.gcc-x64和clang-x64,根据编译器的前端选择就行,例如我的xtensa编译器选的是gcc-x64*/
"includePath": ["${myDefaultIncludePath}", "/another/path"],/*包含路径是包含源文件中包含的头文件(如#include“myHeaderFile.h”)的文件夹。指定IntelliSense引擎在搜索包含的头文件时要使用的路径列表。如果路径以/**结尾,IntelliSense引擎将从该目录开始递归搜索头文件。如果在安装了Visual Studio的Windows上,或者在编译器路径设置中指定了编译器,则无需在此列表中列出系统包含路径*/
"macFrameworkPath": ["/System/Library/Frameworks"],/**/
"defines": ["FOO", "BAR=100"],/*用于智能感知引擎在解析文件时使用的预处理程序定义的列表。可以选择使用=设置一个值,例如VERSION=1,我使用vscode的目的是为了代码的智能提示,并不是要实时检测代码的正确性,所以不必要将在编译时加上的宏定义在这里写上,用browse来自动搜索可用的宏定义就行了*/
"forcedInclude": ["${workspaceFolder}/include/config.h"],/**/
"compilerPath": "/usr/bin/clang",/*用于构建项目的编译器的完整路径,例如/usr/bin/gcc,以启用更精确的智能感知。扩展将查询编译器,以确定系统包含的路径和用于智能感知的默认定义(网易翻译)在交叉编译时,将该字段设置为编译器的绝对路径就行了,例如/root/esp8266/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc*/
"cStandard": "c11",/*用于智能感知的C语言标准版本,根据实际情况确定*/
"cppStandard": "c++17",/*用于智能感知的c++语言标准的版本,根据实际情况确定*/
"compileCommands": "/path/to/compile_commands.json",/*compile_命令的完整路径。工作区的json文件。将使用在此文件中找到的包含路径和定义,而不是为includePath和defines设置设置的值。如果compile commands数据库不包含与在编辑器中打开的文件对应的翻译单元条目,则会出现警告消息,扩展名将使用includePath并定义设置*/
//--/*browse很少,只有三个*/
"browse": {
"path": ["${workspaceFolder}"],/*标记解析器搜索源文件包含的标题的路径列表。如果省略,includePath将用作路径。默认情况下,在这些路径上搜索是递归的。指定*表示非递归搜索。例如:/usr/include将搜索所有子目录,而/usr/include/*不会*/
"limitSymbolsToIncludedHeaders": true,/*如果为true,则标记解析器将只解析源文件直接或间接包含在${workspaceFolder}中的代码文件。如果为false,标记解析器将解析在浏览中指定的路径中找到的所有代码文件。路径列表。*/
"databaseFilename": ""/**/
}
}
],
//建议不要编辑这个字段,它跟踪c_cpp_properties.json文件的当前版本,以便扩展插件知道应该显示什么属性和设置,以及如何将该文件升级到最新版本。
"version": 4
}
3资料
(一)
核心字段含义
env(environment .n环境)
用户自定义变量,可用于在其他配置属性中进行替换,在本例中myDefaultIncludePath即为用户自定义变量,在configurations.includePath字段下被引用。
configurations(configurations n.布局;结构;构造;格局;形状;(计算机的)配置)
一组配置对象,向智能感知引擎提供有关你的项目和首选项的信息。默认情况下,扩展插件会根据操作系统自动创建相关信息,我们自定义配置主要就是修改这里。
version(version n.版本;型式)
建议不要编辑这个字段,它跟踪c_cpp_properties.json文件的当前版本,以便扩展插件知道应该显示什么属性和设置,以及如何将该文件升级到最新版本。
(二)
Configuration字段
name
用来标识配置文件,一般是内核的名字就可以了,如"Linux"
compilerPath(compiler v.编译程序path n.路径;道路;)
用于构建项目的编译器的完整路径,例如/usr/bin/gcc,以启用更精确的智能感知。扩展将查询编译器,以确定系统包含的路径和用于智能感知的默认定义(网易翻译)
在交叉编译时,将该字段设置为编译器的绝对路径就行了,例如/root/esp8266/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc
compilerArgs(argument n.参数;论点; 争论; 论据; 辩论; 争吵; 争辩; 理由;)
编译选项,之所以不重要,是因为defines的问题可以用browse解决,而include问题可以用includePath字段解决,该字段可以不写
intelliSenseMode(intelligence n.智力sense n.感觉v.感觉到)
智能感知模式,有msvc-x64.gcc-x64和clang-x64,根据编译器的前端选择就行,例如我的xtensa编译器选的是gcc-x64
用一张图直观地展现了编译器的整个编译过程:
includePath(重要)
An include path is a folder that contains header files (such as #include “myHeaderFile.h”) that are included in a source file. Specify a list of paths for the IntelliSense engine to use while searching for included header files. If a path ends with /** the IntelliSense engine will do a recursive search for header files starting from that directory. If on Windows with Visual Studio installed, or if a compiler is specified in the compilerPath setting, it is not necessary to list the system include paths in this list.(官方文档)
包含路径是包含源文件中包含的头文件(如#include“myHeaderFile.h”)的文件夹。指定IntelliSense引擎在搜索包含的头文件时要使用的路径列表。如果路径以/结尾,IntelliSense引擎将从该目录开始递归搜索头文件。如果在安装了Visual Studio的Windows上,或者在编译器路径设置中指定了编译器,则无需在此列表中列出系统包含路径
用这个在要包含的主目录后面加上通配符就可以递归搜索,非常方便
defines(define vt.定义; 界定; 明确; 解释)
用于智能感知引擎在解析文件时使用的预处理程序定义的列表。可以选择使用=设置一个值,例如VERSION=1,我使用vscode的目的是为了代码的智能提示,并不是要实时检测代码的正确性,所以不必要将在编译时加上的宏定义在这里写上,用browse来自动搜索可用的宏定义就行了
cStandard(standardn. 标准)
用于智能感知的C语言标准版本,根据实际情况确定
cppStandard
用于智能感知的c++语言标准的版本,根据实际情况确定
configurationProvider(provider n.供应者)
用不到
compileCommands(compilevt. 编写; 编译command n./v.命令)
The full path to the compile_commands.json file for the workspace. The include paths and defines discovered in this file will be used instead of the values set for includePath and defines settings. If the compile commands database does not contain an entry for the translation unit that corresponds to the file you opened in the editor, then a warning message will appear and the extension will use the includePath and defines settings instead.
compile_命令的完整路径。工作区的json文件。将使用在此文件中找到的包含路径和定义,而不是为includePath和defines设置设置的值。如果compile commands数据库不包含与在编辑器中打开的文件对应的翻译单元条目,则会出现警告消息,扩展名将使用includePath并定义设置。用不到,因为有browse
browse(重要)(browse n./v.浏览)
The set of properties used when “C_Cpp.intelliSenseEngine” is set to “Tag Parser” (also referred to as “fuzzy” IntelliSense, or the “browse” engine). These properties are also used by the Go To Definition/Declaration features, or when the “Default” IntelliSense engine is unable to resolve the #includes in your source files(官方文档)
如果只是将需要包含的头文件放在includePath字段中,那么include的问题解决了,但是defines的问题还没有解决,这将会出现一大堆的提示,这些提示大部分都是因为缺少相应的宏定义引起的,而browse可以搜索相应browse.path字段中所有的宏定义,并把缺少的宏定义补全,让Definition/Declaration操作可以无障碍
(三)
browse字段
很少,只有三个
path()
A list of paths for the Tag Parser to search for headers included by your source files. If omitted, includePath will be used as the path. Searching on these paths is recursive by default. Specify * to indicate non-recursive search. For example: /usr/include will search through all subdirectories while /usr/include/* will not(官方文档)标记解析器搜索源文件包含的标题的路径列表。如果省略,includePath将用作路径。默认情况下,在这些路径上搜索是递归的。指定*表示非递归搜索。例如:/usr/include将搜索所有子目录,而/usr/include/*不会
注意通配符问题,与includePath字段不相同
limitSymbolsToIncludedHeaders(limit n./v.限度; 限制;symbol n.象征; 符号; 代号; 记号;vt.用符号代表to included包括header n.用头顶球; 头球; (计算机打印时自动加在各页顶端的)标头,首标;)
When true, the Tag Parser will only parse code files that have been directly or indirectly included by a source file in
w
o
r
k
s
p
a
c
e
F
o
l
d
e
r
.
W
h
e
n
f
a
l
s
e
,
t
h
e
T
a
g
P
a
r
s
e
r
w
i
l
l
p
a
r
s
e
a
l
l
c
o
d
e
f
i
l
e
s
f
o
u
n
d
i
n
t
h
e
p
a
t
h
s
s
p
e
c
i
f
i
e
d
i
n
t
h
e
b
r
o
w
s
e
.
p
a
t
h
l
i
s
t
.
(
官
方
文
档
)
如
果
为
t
r
u
e
,
则
标
记
解
析
器
将
只
解
析
源
文
件
直
接
或
间
接
包
含
在
{workspaceFolder}. When false, the Tag Parser will parse all code files found in the paths specified in the browse.path list.(官方文档)如果为true,则标记解析器将只解析源文件直接或间接包含在
workspaceFolder.Whenfalse,theTagParserwillparseallcodefilesfoundinthepathsspecifiedinthebrowse.pathlist.(官方文档)如果为true,则标记解析器将只解析源文件直接或间接包含在{workspaceFolder}中的代码文件。如果为false,标记解析器将解析在浏览中指定的路径中找到的所有代码文件。路径列表。
通常设置为true,如果有些代码没法智能提示可以将该字段设置为false试试
databaseFilename(database n.(储存在计算机中的)数据库)
用不上