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?
The Concept of C Macros Macros are generally used to define constant values that are being used repeatedly in program. Macros can even accept arguments and such macros are known as function-like macros. It can be useful if tokens are concatenated into code to simplify some complex declarations.
If you find IntelliSense has stopped working, the language service may not be running. Try restarting VS Code and this should solve the issue. If you are still missing IntelliSense features after installing a language extension, open an issue in the repository of the language extension.
Macro is defined by #define directive. There are two types of macros: Object-like Macros. Function-like Macros.
Project makefile defines
are set in .vscode/c_cpp_properties.json
.
"configurations": [ { ... "defines":[ "MYSYMBOL", "MYVALUE=1" ] } ], ...
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 select C/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-reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With