Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code C++ remove 'define' in c_cpp_properties.json

I know it is possible to add defines for Visual Studio Code in c_cpp_properties.json and I manually define __GNUC__ for my code, but is it possible to undo/remove defines that Visual Studio Code assumes for itself? For example if I set intelliSenseMode to clang-x64 the macro __clang__ is defined which completely destroys my intellisense because I don't have appropriate include files for libraries I use and include selection for __clang__ happens before __GNUC__. Same for msvc-x64 value. If I manually #undef __clang__ in my include files then everything is perfect.

Is it possible to undo macro in Visual Studio Code configuration?

like image 694
rmflow Avatar asked May 18 '18 10:05

rmflow


1 Answers

Yes

First, create a header file called, say, vscode-preinclude.h. Put it anywhere; I'll assume it is in the workspace folder (the one that also has .vscode in it). Inside that file use #undef to undefine the symbols you need turned off. Example:

#undef __clang__

Next, use the Command Palette (Ctrl+Shift+P) and open "C/C++: Edit Configurations (UI)". Go down to the bottom and open "Advanced Settings". Scroll down to "Forced include", and add a line:

${workspaceFolder}/vscode-preinclude.h

That's it!

Troubleshooting

If it doesn't work, take a look at the output of the "C/C++: Log Diagnostics" command. It should show something like:

    Forced Includes:
        D:\WRK\LEARN\VSCODE\CPPHELLO\VSCODE-PREINCLUDE.H

in its output.

like image 77
Scott McPeak Avatar answered Oct 04 '22 03:10

Scott McPeak