visual-studio 如何为本机 C++(非托管)开发配置 Visual Studio?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1209497/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:49:21  来源:igfitidea点击:

How to configure Visual Studio for native C++ (unmanaged) development?

c++visual-studio

提问by flesh

I am completely new to C++ development and am trying to learn it in Visual Studio. How can I be sure that I am learning only C++ and not the managed extensions? What configuration settings do I need to change? What project types should I stick to? Any other advice?

我对 C++ 开发完全陌生,正在尝试在 Visual Studio 中学习它。我如何确定我只学习 C++ 而不是托管扩展?我需要更改哪些配置设置?我应该坚持哪些项目类型?还有什么建议吗?

Side issue:
I have tried turning off Language Extensions under

附带问题:
我曾尝试关闭下的语言扩展

Project properties -> C/C++ -> Language -> Disable Language Extensions

项目属性 -> C/C++ -> 语言 -> 禁用语言扩展

but this has generated a compiler error:

但这产生了编译器错误:

Error 1 Command line error D8016 : '/Za' and '/clr' command-line options are incompatible

错误 1 ​​命令行错误 D8016:“/Za”和“/clr”命令行选项不兼容

I've no idea what's going on here ..

我不知道这里发生了什么..

回答by RichieHindle

The fact that you have /clrswitch in there means you're using a .Net project type - you need to choose a "Win32" project type to get a pure C++ project.

/clr在那里切换的事实意味着您使用的是 .Net 项目类型 - 您需要选择“Win32”项目类型才能获得纯 C++ 项目。

Avoid anything calling itself "managed" or "CLR".

避免任何自称为“托管”或“CLR”的东西。

回答by jalf

In brief, all the Win32 C++ projects are native C++.

简而言之,所有的 Win32 C++ 项目都是本机 C++。

The ones including CLR in the name are managed C++.

名称中包含 CLR 的是托管 C++。

Language extensions are nothing to do with .NET. It is a number of vendor-specific extensions to native C++. (So the effect of disabling language extensions is roughly similar specifying --ansi with the G++ compiler)

语言扩展与 .NET 无关。它是本地 C++ 的许多特定于供应商的扩展。(所以禁用语言扩展的效果和用G++编译器指定--ansi大致类似)

/clr is the flag you need to get rid of.

/clr 是您需要摆脱的标志。

回答by Pavel Minaev

So long as you stick to project types under "Win32" node in New Project dialog, you will only be dealing with native code. There's no way to accidentally write some managed code in those projects, unless you go into Project Properties and switch project type to managed.

只要您坚持在“新建项目”对话框中“Win32”节点下的项目类型,您就只会处理本机代码。除非您进入项目属性并将项目类型切换为托管,否则不会意外地在这些项目中编写一些托管代码。