Reputation: 157
I have an embedded project in VisualStudio code which works perfectly fine for the most part. My problem is that somehow _WIN32 is always defined, which leads to wrong includes in some header files.
I guess the problem is an Intellisense issue because the project compiles without any errors (I use the IAR compiler). It's just the error squiggles from Intellisense which display the error. (For example in one header file it trys to open <windows.h> because of the _WIN32 define, which obviously will fail in an embedded project with an embedded compiler, so Intellisense reports that it can't open the header file)
Now, what i tried so far:
Does anyone have an idea why _WIN32 is defined or where it is defined ? How can i tell VisualStudio code / Intellisense to not define _WIN32 ?
Thanks in advance.
Upvotes: 0
Views: 1676
Reputation: 12809
Most likely, the problem is VSCode is using the wrong C++ compiler to gather the predefined macros; that is the likely source of the _WIN32
definition. Use the command Palette (Ctrl+Shift+P) to run "C/C++: Edit Configurations (UI)", then set "Compiler path" to point at your compiler executable (IAR in this case). That should solve the problem because VSCode will then query that compiler to determine the predefined macros.
To confirm the fix, in Command Palette, run "C/C++: Log Diagnostics". The output will show you which compiler VSCode found and what it detected as its built-in include path and preprocessor defines. You should see that _WIN32
is no longer among them. (You might want to run this before changing anything to see the difference.)
Also, you mentioned changing the Intellisense mode. I believe the effect of that switch is related to C++ language dialect issues, especially support for certain bugs in certain compilers. It is unrelated to whether any preprocessor symbols are defined.
(Some of the text in this answer is copied from another answer of mine that more broadly discusses configuring VSCode to emulate a given compiler.)
Upvotes: 1