_WIN32的VSCode轮换定义 [英] VSCode turn of _WIN32 define

查看:97
本文介绍了_WIN32的VSCode轮换定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VisualStudio代码中有一个嵌入式项目,该项目在大多数情况下都能正常工作.我的问题是,总是以某种方式定义_WIN32,这会导致某些头文件中的错误包含.

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.

我猜这是一个Intellisense问题,因为项目编译时没有任何错误(我使用IAR编译器).只是来自Intellisense的错误信息显示了错误.(例如,在一个头文件中,由于_WIN32定义,它尝试打开< windows.h> ;,显然,在带有嵌入式编译器的嵌入式项目中,此操作将失败,因此Intellisense报告它无法打开头文件)

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:

  1. 更改Intellisense模式,但是即使我将其切换为ARM的gcc或clang,_WIN32仍保持定义状态
  2. 试图从代码中删除_WIN32定义,但是VSCode似乎在内部定义了它(如果有意义的话?).我看了这线程,他们尝试回答定义_WIN32的问题.但这也无济于事.
  1. Changing the Intellisense mode but even if I switch it to gcc or clang for ARM, _WIN32 stays defined
  2. Trying to remove the _WIN32 define from code, but it seems that VSCode defines it internally (if that makes any sense ?). I looked at this thread where they try to answer the question where _WIN32 is defined. But that didn't help me either.

有人知道为什么定义_WIN32或定义哪里吗?如何告诉VisualStudio代码/Intellisense 定义_WIN32?

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 ?

谢谢.

推荐答案

最有可能的问题是,VSCode使用了错误的C ++编译器来收集预定义的宏.那可能是 _WIN32 定义的来源.使用命令面板(Ctrl + Shift + P)运行"C/C ++:编辑配置(UI)",然后在设置路径"中设置编译器路径".指向您的编译器可执行文件(在这种情况下为IAR).那应该可以解决问题,因为VSCode随后将查询该编译器以确定预定义的宏.

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.

为确认该修复,在命令面板中,运行"C/C ++:日志诊断".输出将显示给您找到哪个编译器VSCode以及其内置的include路径和预处理器定义所检测到的内容.您应该看到 _WIN32 不再在其中.(您可能需要先执行此操作,然后再进行任何更改以查看区别.)

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.)

您还提到了更改Intellisense模式.我相信该切换的效果与C ++语言方言问题有关,尤其是对某些编译器中某些错误的支持.与是否定义任何预处理器符号无关.

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.

(此答案中的某些内容是从我的另一个答案中复制的,该答案更广泛地讨论了配置VSCode以进行仿真给定的编译器.)

(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.)

这篇关于_WIN32的VSCode轮换定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆