如何让 VS Code 识别 C++ 中不同的包含路径?

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

当我写

#include <ncurses.h>
时,IntelliSense 给我一个错误:

#include errors detected based on information provided by the configurationProvider setting. Squiggles are disabled for this translation unit
cannot open source file "ncurses.h"

当我写

#include <ncurses/ncurses.h>
时,它可以正常工作,没有任何错误,但我希望它可以在没有
ncurses/
的情况下工作。

ncurses.h
文件位于以下路径:
D:/msys64/mingw64/include/ncurses

我尝试过的(没有成功):

  1. 我已经尝试通过将
    tasks.json
    放入其中来修改
    -I/mingw64/include/ncurses
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "D:\\msys64\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-I/mingw64/include/ncurses",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
  1. 我还尝试通过添加 includePath 来修改
    c_cpp_properties.json
    (我也尝试过强制包含):
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "D:/msys64/mingw64/include/ncurses"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "cStandard": "c17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "windows-gcc-x64",
            "configurationProvider": "ms-vscode.makefile-tools"
        }
    ],
    "version": 4
}

需要注意的一件事:当我运行我的 Makefile 时,它可以正常工作,没有任何错误(我必须在那里添加一个包含):

CXX := c++
CXXFLAGS := -Wall -std=c++20

# Contain path for any includes (headers)
# Depending on your platform: Include a path to boost, on linux should be 
# /usr/local/include, on mac could be /opt/homebrew/include
INCLUDES := -I/mingw64/include/ncurses -I./include

# Contains libraries we need to (-L is directory search path, -l is lib)
LDFLAGS = -L/usr/local/lib 
LDLIBS = -lncurses

SRCDIR := ./src
BREAKOUT_OBJECTS := controller_console.o model_simulator_breakout.o observer.o view_console.o main.o

breakout: $(BREAKOUT_OBJECTS)
    $(CXX) $^ -o $@ $(LDLIBS)
    
%.o: $(SRCDIR)/%.cpp
    $(CXX) $(INCLUDES) $(CXXFLAGS) -c $^ -o $@ -DNCURSES_STATIC
clean:
    test ! -f breakout || rm breakout
    rm *.o

但我希望 IntelliSense 也能识别

ncurses.h
,这样我就可以自动完成并且不会出现错误。

c++ visual-studio-code include intellisense ncurses
1个回答
0
投票

好的,所以对我有用的是从

c_cpp_properties.json
中删除以下行:

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

设置此值后,VS Code 似乎会忽略 includePaths

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.