Home>Article>Development Tools> Vscode has a header file and cannot be compiled. Solution
在使用VSCODE进行C语言程序设计时,如果用到了头文件声明函数,.c文件定义函数,在编译时尽管已经引用了相应的头文件,VSCODE文本编辑器也没有报错,但仍然无法编译。
错误提示如下:
d:/ComputerHomework/2019_winter/main.c:10: undefined reference to `ReadPathTkFile'
这是由于VSCODE实际上是一个文本编辑器,不是一个IDE,它不会自动链接项目通过头文件引用的.c文件。要解决这个问题,就要告诉编译器需要链接哪些文件。
解决方法
在当前路径下的.vscode文件夹中找到tasks.json,找到"args"属性,在其中"-g"后,"-o"前加入"${fileDirname}\\YourcFileName.c",每组字符串以逗号分隔。YourcFileName.c即项目中要参与编译的文件名。
样例如下(仅参考填写格式,具体参数不相同正常)
{ "tasks": [ { "type": "shell", "label": "gcc.exe build active file", "command": "C:\\mingw64\\bin\\gcc.exe", "args": [ "-g", "${file}", "${fileDirname}\\IstkFile.c", "${fileDirname}\\PrintQuestion.c", "${fileDirname}\\MarkingSystemLib.c", "${fileDirname}\\zqyLib.c", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "C:\\mingw64\\bin" } } ], "version": "2.0.0" }
推荐学习:vscode教程
The above is the detailed content of Vscode has a header file and cannot be compiled. Solution. For more information, please follow other related articles on the PHP Chinese website!