简体   繁体   English

Visual Studio Code C/C++ 包含路径不适用于自定义头文件

[英]Visual Studio Code C/C++ Include Path not working for custom header files

I'm writing with C using VSC and MinGW GCC.我正在使用 VSC 和 MinGW GCC 用 C 编写。 I can include default headers like these:我可以包含这样的默认标题:

#include <stdio.h>
#include <Windows.h>

However, when I create my own header file in the subdirectory "Source", let's say it's name is "Test.h", if I try to include it, there is no error in VSC , only when I try to compile with GCC (by typing gcc Main.c -o Test.exe) do I get the error that says this:但是,当我在子目录“Source”中创建自己的头文件时,假设它的名称是“Test.h”,如果我尝试包含它,则 VSC 中没有错误,只有当我尝试使用 GCC 进行编译时(通过键入 gcc Main.c -o Test.exe) 我是否收到错误消息:

Main.c5:10: fatal error: test.h: No such file or directory. 
  #include "test.h"

Here is my c_cpp_properties.json file:这是我的 c_cpp_properties.json 文件:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/Source"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

As well as this,除了这个,

Whenever I compile and this error occurs, if I open up "test.h", I get this error in VSC :每当我编译并发生此错误时,如果我打开“test.h”,我会在 VSC 中收到此错误:

https://prnt.sc/1hxct6g (screenshot) https://prnt.sc/1hxct6g (截图)

If I follow this error, it opens up my C/C++ configuration, and tells me to edit my includePath settings.如果我遵循这个错误,它会打开我的 C/C++ 配置,并告诉我编辑我的 includePath 设置。

I've tried multiple things, none have worked.我尝试了很多东西,没有一个奏效。 Any help?有什么帮助吗?

Your include path is (where your header files are): "${workspaceFolder}/Source"您的包含路径是(您的头文件所在的位置): "${workspaceFolder}/Source"

If you run your compiler from within your workspace folder then you have to add the -I option to the command line:如果从工作区文件夹中运行编译器,则必须在命令行中添加-I选项:

gcc -ISource Main.c -o Test.exe

More info : GCC - Search Path更多信息GCC - 搜索路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM