When using the "Default"
intellisense engine, some of the symbols in my C++ project cannot be resolved. It turns out that it's because they are in headers where they are guarded by an #ifdef
that depends on a macro passed to gcc with the -D
flag by the makefile. How can I tell the intellisense engine about these defines so that it is able to compile those parts of the header?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Visual Studio Code, MAC OS X, OmniSharp server is
- Class layout in C++: Why are members sometimes ord
- Omnisharp in VS Code produces a lot of warnings ab
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
The other answers so far have two issues that don't seem trivial to fix:
There might be times where different source files need different compiler flags.
It could be painfully tedious to manually figure out what compiler flags are necessary and manually add them.
Luckily, VS Code's C/C++ extension supports a compile_commands.json database. This stores information specific to every individual source file including the defines, include directories, and other compiler command line flags. I just posted a more detailed description of how to generate one and get VS Code to use it over here: https://stackoverflow.com/a/59618515/12663912
Project makefile
defines
are set in.vscode/c_cpp_properties.json
.Here are some methods to open
c_cpp_properties.json
:Find a green squiggle on something like an include statement that Intellisense can't resolve. Hover around and click the lightbulb that appears (which is tiny and a bit of a game to click). It will open the project config file in the editor.
Same as above, but put cursor on the green squiggle line and press
Ctrl
+.
.Use the command pallet:
ctrl
+shift
+P
, then selectC/C++: Edit configurations (JSON)
.If the file already exists in your .vscode folder, open it with
File
->Open
.Although vscode will reprocess the settings after
c_cpp_properties.json
is modified, I found a restart is sometimes required when changing values.There is basic and incomplete information here: https://code.visualstudio.com/docs/languages/cpp
This is a good link about the
c_cpp_properties.json
file itself: https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-referenceThis capability has now been added: https://github.com/Microsoft/vscode-cpptools/issues/304