vscode cmake头文件无法跳转

采用vscode打开cmake配置的c++项目时,头文件夹显示找不到(头文件被红色波纹线标记),右键变量执行Go To Definiton也无法跳转

这种情况需要在c_cpp_properties.json中添加一个配置项,使配置的信息来源与cmake

"configurationProvider": "ms-vscode.cmake-tools"

Cmd + Shfit + P,输入edit configuration:

编辑c_cpp_properties.json配置文件:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "D:/Program Files/Huawei/DevEco Studio/sdk/default/openharmony/native/llvm/bin/clang.exe",
            "cStandard": "c89",
            "cppStandard": "c++98",
            "intelliSenseMode": "linux-clang-arm64",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}

这里解释一下这几个重要配置项的作用:

name:配置名称,会显示在状态栏上。
includePath:VS Code搜索include头文件的路径(后面会被Cmake tools取代)。
compilerPath:编译器路径,这里我选择的llvm的clang。这也是目前NDK官方指定的,其他编译器都被Google删掉了...
configurationProvider:这个配置是告诉VS code,让Cmake Tools插件根据CMakeLists.txt的配置来指定C/C++的代码环境,如在CMakeLists.txt中配置了 link_directories(dir_xx)命令,VS Code就能正确识别出 #Include<dir_xx/xxx.h>头文件。同时也就取代了上面的 includePath配置。

不过vscode自带的edit configuration(UI)解释的更全面

参考:

https://blog.youkuaiyun.com/lizy_fish/article/details/106376080

https://zhuanlan.zhihu.com/p/157362239

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值