包含路径在VSCode中的C调试器中不起作用 – Raspberry Pi

huangapple go评论77阅读模式
英文:

Include path not working for C debugger in VSCode - Raspberry Pi

问题

你正在使用VS Code通过SSH远程连接到树莓派进行我的第一个C项目。代码可以成功编译,但调试器找不到头文件。我已经查看了现有的问题,但建议的解决方案未能解决我的问题。

如果我将头文件放在项目的根目录中,调试器就可以找到该文件。

源代码,第18行:

#include "mfrc522.h"

该文件位于include文件夹中:
包含路径在VSCode中的C调试器中不起作用 – Raspberry Pi

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:
包含路径在VSCode中的C调试器中不起作用 – Raspberry Pi

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.

huangapple
  • 本文由 发表于 2023年6月29日 11:55:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577969.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定