0

(Note: this EDITed version is a truncated part of the original OP (kept at the bottom), after this correct comment. Two separate questions 1 and 2 were also posted. All this improves SO.)

I am slowly migrating from Eclipse CDT to VSCode with C/C++ Extension Pack. I am working under Ubuntu 22, with g++.

When working in Eclipse, I am used to compiling/linking via g++ from within VSC, and getting a list of compilation errors.

Eclipse CDT has its own Code Analysis tool. This tool "knows quite a bit" about C++ (although "much less" than the compiler) and produces further errors and warnings, without compiling, that add to the list above. But it sometimes reports false positives, where there is nothing to fix (at least when compiling with g++).

To avoid these errors tainting the list, I can turn off CodeAn (I don't know if VSC lingo has a name for that). Note that this still allows for quick-navigating (error list) -> (code), it only removes error reporting by the Eclipse Code Analysis, keeping only actual compilation errors.

Below I am adding two images of the configuration menu in Eclipse. Scrolling down there are many other cases that can be detected by CodeAn.

Can I perform this with VSCode? Note that I am referring to VSCode. Disabling CodeAn for VS might be different.

enter image description here

enter image description here


Original question (likely to be removed shortly to reduce the clutter)

I have a large C++ package, with its own CMake files. Note that, when working at the command prompt, I use CMake to generate makefiles, and then compiling/linking with make <flags> <target>. I don't use cmake --build, e.g. When working in Eclipse, I am used to:

  1. Setting up make targets so I compile/link with a double click.
  2. Whenever a compilation error shows up, I can double click on the error in the list of errors to go straight to the line producing the error.

Eclipse CDT has its own Code Analysis tool. This tool "knows quite a bit" about C++ (although "much less" than the compiler) and produces a list of errors and warnings, without compiling. But it sometimes reports false positives, where there is nothing to fix (at least when compiling with g++).

  1. To avoid these errors tainting the list, I can turn off CodeAn. Note that this still allows for navigating the code, it only removes error reporting by the Eclipse Code Analysis. These are two images of the configuration menu in Eclipse. Scrolling down there are many other cases that can be detected by CodeAn.

[IMAGES]

Can I perform #2 with VSCode? I tried a few things for #1 (which is likely a prerequisite for #2), with json files, but I could not make it work. EDIT: This question was split into here. I will shortly adapt this OP.

16
  • 1
    Your title seems contradictory to what you're actually asking in the question. You want to disable VSC's debug/code analysis that comes with the MS C/C++ Extensions, but you want it to perform Code Analysis similar to Eclipse? Commented Oct 12, 2023 at 18:12
  • No. I want VSC not to perform any code analysis, the same as I ask Eclipse CDT (#3). All error reporting should come from the build process (i.e., g++), properly interfaced with the IDE. If this interface works properly, navigation to real compilation error lines should be easy (#2). Commented Oct 12, 2023 at 18:16
  • I don't understand, why are you talking about (3) and code analysis at all? If your goal is, as stated in (2), to jump to errors from the build log, you just need to Alt+Click (the modifier can be different on your platform) the filename:line in the build log, and it will take you to that file and line. Commented Oct 31, 2023 at 11:28
  • Doesn't MS VS Project |> Properties |> Code Analysis allow you to disable it completely and/or configure which rules the MSC analyser will apply? Commented Oct 31, 2023 at 16:42
  • 1) what do you mean by "code navigation"? you mean things like "go to definition"? 2) I've edited my answer slightly 3) please add the link to your new question here. Commented Oct 31, 2023 at 20:00

1 Answer 1

1

In case of CMake with the CMake Tools extension, (at least in my experience) the behaviour is already like that. You might find my answer to How can I set up C/C++ IntelliSense for a CMake project in VS Code? helpful.

Otherwise, just disable the Cpptools IntelliSense ("C_Cpp.intelliSenseEngine": "disabled", in settings.json) and use a build task with a problem matcher such as the provided $gcc one. Even without a problem matcher, the integrated terminal in VS Code supports several common file+line patterns and will make those patterns into links that you can click into when holding down your link modifier (typically ctrl/cmd or alt/opt).

Sign up to request clarification or add additional context in comments.

3 Comments

As mentioned in comment above, and further clarified in edited OP, when working at the command prompt I use CMake to generate makefiles, and then compiling/linking with make <flags> <target>. I don't use cmake --build, e.g. So in practice my use of cmake (and the CMake Tools extension) is irrelevant. I would still like to have IntelliSense features, which has nothing to do with CMake; I don't understand why not using CMake would amount to disabling IntelliSense. I will try to learn how to setup all this, with make targets.
@sancho.sReinstateMonicaCellio If you're using CMake, IMO it's a waste not to use CMake Tools. And even if you insist not to use CMake tools for some odd reason, I don't see why not use cmake --build. The IntelliSense does have to do with CMake, because if you want to get it in VS Code when building with CMake, the most common and easy way is to use the CMake Tools extension and configure the intellisense provider as described in the linked Q&A.
Not using cmake --build was simply an "inherited" procedure in a large project, and I never bothered changing that. If I were to start from scratch I would probably do so, and I might in the future.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.