- 问题介绍
需要用到vs code进行多文件编译,注意是多文件编译,出现了undefined reference to ‘xxx’ 的问题。查找了网上很多资料,结果都是让修改Tasks.json 或者是lunch.json文件。更改以后发现自己的问题不在这
undefined reference to `Swap'
undefined reference to `Empty'
undefined reference to `LocateElem'
undefined reference to `InitList'
undefined reference to `ListInsert'
undefined reference to `PrintList'
- 问题关键
网上有很多关于一个插件Code.runner的安装,关键就在这里,一定要看你的Vs code 是否安装了这个插件,它会在Setting.json的配置里面有如下的代码:
"code-runner.executorMap": {
"c": "gcc '$filename' -o '$fileNameWithoutExt.exe' -Wall -O2 -m64 -lm -static-libgcc -std=c11 -fexec-charset=GBK && &'./$fileNameWithoutExt.exe'",
"cpp": "g++ '$filename' -o '$fileNameWithoutExt.exe' -Wall -O2 -m64 -static-libgcc -std=c++14 -fexec-charset=GBK && &'./$fileNameWithoutExt.exe'"
// "c": "gcc $fileName -o $fileNameWithoutExt.exe -Wall -O2 -m64 -lm -static-libgcc -std=c11 -fexec-charset=GBK && $dir$fileNameWithoutExt.exe",
// "cpp": "g++ $fileName -o $fileNameWithoutExt.exe -Wall -O2 -m64 -static-libgcc -std=c++14 -fexec-charset=GBK && $dir$fileNameWithoutExt.exe"
}, // 右键run code时运行的命令;未注释的仅适用于PowerShell(Win10默认)和pwsh,文件名中有空格也可以编译运行;注释掉的适用于cmd(win7默认)、PS和bash,但文件名中有空格时无法运行
- 方案一: 如果你坚持要用Code.Runner这个插件请把上面的Setting.json中的代码改为下面的,其实 就是把filename更改了,变为你要编译的所有的.c/.cpp的文件。改为*.c 或者是*.cpp。在用Code.Runner这个插件的时候Tasks.json和Lunch.json的配置是不起作用的(我感觉是这样)
"code-runner.executorMap": {
"c": "gcc '*.c' -o '$fileNameWithoutExt.exe' -Wall -O2 -m64 -lm -static-libgcc -std=c11 -fexec-charset=GBK && &'./$fileNameWithoutExt.exe'",
"cpp": "g++ '*.cpp' -o '$fileNameWithoutExt.exe' -Wall -O2 -m64 -static-libgcc -std=c++14 -fexec-charset=GBK && &'./$fileNameWithoutExt.exe'"
// "c": "gcc $fileName -o $fileNameWithoutExt.exe -Wall -O2 -m64 -lm -static-libgcc -std=c11 -fexec-charset=GBK && $dir$fileNameWithoutExt.exe",
// "cpp": "g++ $fileName -o $fileNameWithoutExt.exe -Wall -O2 -m64 -static-libgcc -std=c++14 -fexec-charset=GBK && $dir$fileNameWithoutExt.exe"
}, // 右键run code时运行的命令;未注释的仅适用于PowerShell(Win10默认)和pwsh,文件名中有空格也可以编译运行;注释掉的适用于cmd(win7默认)、PS和bash,但文件名中有空格时无法运行
-
方案二: 放弃使用Code.Runner 这个插件,首先要把这个插件进行禁用。然后就按照其他博客介绍的方案,更改lunch.json和Tasks.json中的配置就可以了
以后有问题,再做补充。。