0

I'm a noob please don't hate me.

I'm using cmake and vscode for a cpp project.

  • Compiling is fine but clang says it can't find my headers and underline them although it also show me the path so it knows where they are... file not found
  • including the relative path fixes the problem but its less clean :
"../include/myHeader.hpp" vs "myHeader.hpp"

I have export compile command on in my presets :

{
    "version": 2,
    "configurePresets": [
        {
            "name": "debug",
            "displayName": "Debug",
            "binaryDir": "${sourceDir}/build",
            "generator": "Unix Makefiles",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Debug",
                "CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
                "CMAKE_CXX_FLAGS_INIT": "-std=c++17 -g -Wall -Wextra -Wpedantic -Werror -Weffc++  -Wshadow -O0"
            }
        },
        {
            "name": "release",
            "displayName": "Release",
            "binaryDir": "${sourceDir}/build",
            "generator": "Unix Makefiles",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Release",
                "CMAKE_CXX_FLAGS_INIT": "-std=c++17 -march=native -flto -O3 -DNDEBUG"
            }
        }
    ]
}

and in my vscode settings:

     "C_Cpp.intelliSenseEngine": "disabled",
    "C_Cpp.configurationWarnings": "disabled",
    "clangd.path": "/home/pa/.config/Code/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/16.0.2/clangd_16.0.2/bin/clangd",
    "clangd.arguments": [
        "-log=verbose",
        "-pretty",
        "--background-index",
        "--compile-commands-dir=${workspaceFolder}/build/",
        "--completion-style=detailed"
        // "--query-driver=/bin/arm-buildroot-linux-gnueabihf-g++", // for cross-compile usage
    ],
    "[cpp]": {
        "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"

If someone knows how to fix this it would be great...
Thanks !

3
  • VSCode is a very advanced, complex development tool that's designed for highly skilled, experienced developers who have a wide range of domain knowledge, like the JSON configuration syntax, and familiarity with obscure compiler flags and options. It is not meant to be used for people who are just starting out learning C++ and who do not have established development experience, those people will find other development environments, like VS community edition (Windows) or emacs+make (Linux, MacOS), easier to use. Commented Dec 13, 2023 at 16:28
  • 1
    'heatFin.hpp' file not found heatFin.hpp Where do you get this error message? It's also unclear how you have VSCode setup. You don't appear to be following the official guide however I am not sure if you are using CMakeTools or code-runner or some other build method. You may just need to set the include path in c_cpp_properties.json: https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference
    – drescherjm
    Commented Dec 13, 2023 at 16:44
  • @SamVarshavchik I agree that beginners are better off with a turn-key IDE like Visual Studio Community, CLion etc. However, having used emacs with bells and whistles for many years, and VS Code for a few, I disagree that emacs or makefiles or easier than VS Code or CMake. The unfortunate thing is that although as it stands setting up VS Code for C++ development with CMake is straightforward, the online tutorials provided are terrible, and lead beginners down all kinds of blind alleys.
    – TooTone
    Commented Dec 13, 2023 at 17:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.