You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code CPPTools中${workspaceFolder}/**是否真的支持递归搜索?

VS Code C/C++ Tools扩展无法递归识别include路径问题

环境与问题描述

  • VS Code版本:1.74
  • C/C++ Tools扩展版本:1.13.8
  • 工作区路径:.../rd-infra/arm-tf,包含ARM参考方案的C代码

工作区默认includePath配置包含"${workspaceFolder}/**",但源文件.../rd-infra/arm-tf/bl1/bl1_main.c中第二行的#include <platform_def.h>出现波浪线,报错:

cannot open source file "platform_def.h"C/C++(1696)

右键选择「转到定义」也失败。

搜索代码树找到约74个platform_def.h文件,例如:

~/Projects/ARMFVPs/FVP_RD_N2/rd-infra/arm-tf$ find . -name 'platform_def.h'
./plat/intel/soc/common/include/platform_def.h
./plat/st/stm32mp1/include/platform_def.h
./plat/hisilicon/poplar/include/platform_def.h
./plat/hisilicon/hikey960/include/platform_def.h
./plat/hisilicon/hikey/include/platform_def.h
./plat/mediatek/mt8186/include/platform_def.h
...

本以为会出现多文件选择的情况,实际却是找不到文件的错误。

尝试的解决操作及结果

  1. 添加编译器路径
    修改.vscode/c_cpp_properties.json,指定编译器路径:

    {
        "configurations": [
            {
                "name": "Linux",
                "includePath": [
                    "${workspaceFolder}/**"
                ],
                "defines": [],
                "compilerPath": "${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc",
                "cStandard": "gnu17",
                "cppStandard": "gnu++14",
                "intelliSenseMode": "linux-gcc-arm64"
            }
        ],
        "version": 4
    }
    

    问题未解决,怀疑${workspaceFolder}/**未进行递归搜索。

  2. 添加具体包含目录
    在includePath中添加对应场景的目录:

    {
        "configurations": [
            {
                "name": "Linux",
                "includePath": [
                    "${workspaceFolder}/plat/arm/board/rdn2/include",
                    "${workspaceFolder}/**"
                ],
                "defines": [],
                "compilerPath": "${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc",
                "cStandard": "gnu17",
                "cppStandard": "gnu++14",
                "intelliSenseMode": "linux-gcc-arm64"
            }
        ],
        "version": 4
    }
    

    此时platform_def.h的波浪线消失,「转到定义」可打开对应文件,但该文件中的#include <lib/utils_def.h>又出现相同的1696错误。该文件实际路径为./include/lib/utils_def.h,说明${workspaceFolder}/**甚至无法搜索到一级子目录。

  3. 使用完整路径
    尝试将includePath改为完整路径:

    {
        "configurations": [
            {
                "name": "Linux",
                "includePath": [
                    "${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/arm-tf/**"
                ],
                "defines": [],
                "compilerPath": "${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc",
                "cStandard": "gnu17",
                "cppStandard": "gnu++14",
                "intelliSenseMode": "linux-gcc-arm64"
            }
        ],
        "version": 4
    }
    

    仍出现无法打开platform_def.h的错误,怀疑是否误解了/**的用法。

补充信息

编辑1

预定义变量展开结果:

userHome:        /home/rtillery
workspaceFolder: /home/rtillery/Projects/ARMFVPs/FVP_RD_N2/rd-infra/arm-tf
compiler path:   /home/rtillery/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc

验证编译器路径存在,但VS Code两次提示:

[12/20/2022, 10:47:36 AM] Unable to resolve configuration with compilerPath "${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc".  Using "/usr/bin/gcc" instead.

不确定编译器配置问题与路径搜索是否相关,添加compilerPath仅为尝试操作。

编辑2

${userHome}变量展开异常:问题面板显示编译器路径被解析为/home/rtillery/Projects/ARMFVPs/FVP_RD_N2/rd-infra/arm-tf/${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/...,将其替换为基于${workspaceFolder}的路径:

"compilerPath": "${workspaceFolder}/../tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc"

后,该路径错误消失。

编辑3

已提交相关Bug到GitHub。


内容的提问来源于stack exchange,提问作者rtillery

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 18:40:58