英文:
Include path not working for C debugger in VSCode - Raspberry Pi
问题
你正在使用VS Code通过SSH远程连接到树莓派进行我的第一个C项目。代码可以成功编译,但调试器找不到头文件。我已经查看了现有的问题,但建议的解决方案未能解决我的问题。
如果我将头文件放在项目的根目录中,调试器就可以找到该文件。
源代码,第18行:
#include "mfrc522.h"
tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"--include-directory=${fileDirname}/**",
"--include-directory=${fileDirname}/include/**",
"--include-directory=${fileDirname}/src/*/*.c",
"--include-directory=${fileDirname}/*.c"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/include/**",
"${workspaceFolder}/**",
"${workspaceFolder}/src",
"${workspaceFolder}/src/*",
"${workspaceFolder}/src/*/*.c"
],
"browse": {
"path": [
"${workspaceFolder}/include/**",
"${workspaceFolder}/**",
"${workspaceFolder}/src",
"${workspaceFolder}/src/*",
"${workspaceFolder}/src/*/*.c"
]
},
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-arm64"
}
],
"version": 4
}
结果错误:
main.c:18:10: 致命错误: mfrc522.h: 没有那个文件或目录
编译已终止。
英文:
I am using VS Code remote via SSH to Raspberry Pi for my first C project. The code compiles without a problem, but the debugger can't find the header files. I have reviewed existing questions but the suggested solutions are not solving my problem.
If I place the header file in the root of my project, the file is found by the debugger.
Source, line 18:
#include "mfrc522.h"
The file is available in include
folder:
tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"--include-directory=${fileDirname}/**",
"--include-directory=${fileDirname}/include/**",
"--include-directory=${fileDirname}/src/*/*.c",
"--include-directory=${fileDirname}/*.c"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/include/**",
"${workspaceFolder}/**",
"${workspaceFolder}/src",
"${workspaceFolder}/src/*",
"${workspaceFolder}/src/*/*.c"
],
"browse": {
"path": [
"${workspaceFolder}/include/**",
"${workspaceFolder}/**",
"${workspaceFolder}/src",
"${workspaceFolder}/src/*",
"${workspaceFolder}/src/*/*.c"
]
},
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-arm64"
}
],
"version": 4
}
Resulting error:
> main.c:18:10: fatal error: mfrc522.h: No such file or directory
compilation terminated.
答案1
得分: 0
我之前没有看到bko的这个答案,似乎已经解决了包含头文件的问题。
对我来说解决问题的方法就是只输入文件夹路径,不要加上/*或/**,然后它会提示我是否要为这个文件夹启用智能感知,我允许了并且它起作用了。
英文:
I had not seen this answer by bko earlier, which seems to have overcome the issue of including the header files.
> What solved it for me was to just type folder path without /* or /** Then it prompted me if I want to enable Intellisense for this folder and I allowed it and it worked.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论