我如何获得自定义包含路径以在 visual studio 代码中工作?

问题描述 投票:0回答:0

我知道这是一个烦人的菜鸟问题,我已经尝试了一个小时来尝试弄清楚如何让 gcc 识别我的 GLFW 包含。智能感知目前表示没有任何问题。这是我当前的代码在 main.c 中的样子:

#include <stdio.h>
#include <Include\glfw3.h>

int main()
{
    printf("hello world");
    getch();
}

当我尝试编译它时:

PS D:\github\c> cd "d:\github\c\" ; if ($?) { gcc main.c -o main } ; if ($?) { .\main }
main.c:2:10: fatal error: glfw3.h: No such file or directory
    2 | #include <glfw3.h>
      |          ^~~~~~~~~
compilation terminated.

我试过编辑 c_cpp_properties.json,这是它目前的样子:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${default}",
                "${workspaceFolder}",
                "${workspaceFolder}/**",
                "D:\\github\\c\\Include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\msys64\\mingw64\\bin\\gcc.exe",
            "cStandard": "gnu17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

我无法让它工作,所以我也尝试编辑 tasks.json:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe build active file",
            "command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
            "args": [
                
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "-I\"${workspaceFolder}/include**\"",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

这个,也没用。

最后我尝试手动输入它,它确实正确编译了我无法理解的原因。

PS D:\github\c> gcc main.c -o main.exe -I"Include" -I"libs"
main.c: In function 'main':
main.c:7:5: warning: implicit declaration of function 'getch'; did you mean 'getc'? [-Wimplicit-function-declaration]
    7 |     getch();
      |     ^~~~~
      |     getc

老实说,我对上帝感到困惑,谷歌似乎没有针对我的具体问题的结果。

请不要问我一个愚蠢的问题

c++ c visual-studio-code include
© www.soinside.com 2019 - 2024. All rights reserved.