VS Code C++:不准确的系统 includePath 错误(wchar.h、boost/lambda/lambda.hpp)

the*_*ter 4 c++ g++ clang++ visual-studio-code

在 Mac OS Mojave 10.14.6 上使用 VS Code 处理一个奇怪的包含问题。

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/ajm/Projects/restaurant/cpp/sim/src/main.cpp).C/C++(1696)
cannot open source file "wchar.h" (dependency of "iostream")
Run Code Online (Sandbox Code Playgroud)

请注意,这种情况是在我将 MacOS CommandLineTools 更新为xcode-select --install.

我的编译器路径在 VS Code 中是

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
Run Code Online (Sandbox Code Playgroud)

我的 includePath 是

${workspaceFolder}/**
${BOOST_ROOT}/**
Run Code Online (Sandbox Code Playgroud)

当我添加/Library/Developer/CommandLineTools/usr/include/c++/v1/**到我的 includePath 并将编译器路径更改为 时/usr/bin/g++,STL 包含问题消失了,我得到了这个:

cannot open source file "boost/lambda/lambda.hpp"
Run Code Online (Sandbox Code Playgroud)

请注意,当我从命令行构建程序时,它运行得很好;一切都按其应有的样子被发现。

这是我的 Makefile:

PROG = sim
CC = g++
CPPFLAGS = -g -Wall -I$(SDIR) -I$(ODIR) -I$(BOOST_ROOT)
ODIR = ./bin
SDIR = ./src
OBJS = $(ODIR)/main.o

$(PROG) : $(OBJS)
        $(CC) $(CPPFLAGS) -o $(PROG) $(OBJS)
$(ODIR)/%.o : $(SDIR)/%.cpp
        $(CC) $(CPPFLAGS) -c $< -o $@
Run Code Online (Sandbox Code Playgroud)

运行输出make

g++ -g -Wall -I./src -I./bin -I/usr/local/boost_1_72_0 -c src/main.cpp -o bin/main.o
g++ -g -Wall -I./src -I./bin -I/usr/local/boost_1_72_0 -o sim ./bin/main.o
Run Code Online (Sandbox Code Playgroud)

我的简单程序 main.cpp:

#include <iostream>
#include <boost/lambda/lambda.hpp>

int main()
{
    using namespace boost::lambda;
    std::cout << "Hello World!\n";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这不是一个生死存亡的问题;我真的只是想知道为什么 VS Code 无法正确找到包含头。我的代码仍然有效,但是当它们不准确时,红色波浪线非常烦人。我不想关闭它们,因为当它们正确时,它们会很有帮助。

如果这不是发布此问题的正确位置,请告诉我;我可以将其发布到其他地方。

如果您需要更多详细信息,请告诉我。在此先感谢您的帮助。

干杯

小智 5

您可能已经解决了这个问题,但无论如何我通过运行解决了类似的问题g++ -v -E -x c++ -。这列出了编译器使用的所有目录。确保将所有内容都放在 includePath 中,它应该可以工作。