c++visual-studio-codeclangd

Visual Studio Code and Clangd include errors


I have a including problems when trying to use clangd.

Heres the latest i've tried:

I've tested it with these: Test main.cpp:

#include <iostream>

int main() {
    std::cout << "IT WORKS\n";
    return 0;
}

Test CMakeList.txt:

cmake_minimum_required(VERSION 3.1)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(test)

add_executable(
    ${PROJECT_NAME}
    ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
)

Which I have initialized with mkdir build && cd build && cmake ../ && make && ./test The program does the "IT WORKS" cout in the terminal right but VS Code is showing clang errors with <iostream> and std for not recognizing them.


Solution

  • Found this from another stack overflow post and it did the trick:

    "I spoke to a colleague who told me that gcc-12 was included in ubuntu 22.04 an created some mess with clang. To solve the issue, I did

    sudo apt install g++-12

    and now it works well."