简体   繁体   English

Windows 是否有集成的内置 C/C++ 编译器包?

[英]Has Windows an integrated built-in C/C++ compiler package?

I would like to be able to compile C and C++ code under the Windows environment without using an IDE, just by using the Windows Command prompt (cmd.exe).我希望能够在不使用 IDE 的情况下在 Windows 环境下编译 C 和 C++ 代码,只需使用 Windows 命令提示符 (cmd.exe)。

I come from Linux, where you are be able to install the gcc package with just a command in the terminal:我来自 Linux,您可以在终端中使用命令安装gcc包:

$ sudo apt install gcc

I wonder if there is a C/C++ compiler collection in a package inside the Windows install folders, just like the ones in Linux, I just need to install.我想知道Windows安装文件夹内的包中是否有C/C++编译器集合,就像Linux中的一样,我只需要安装。

What also gives me a reason to ask this question is:也让我有理由问这个问题的是:

Since the kernel of Windows and the Windows API are written in C, and many of the high-level applications of the actual Windows 10 release are written in C++, it would be reasonable to also directly provide a suitable compiler suite.由于 Windows 的内核和 Windows API 是用 C 编写的,而实际 Windows 10 版本的许多高级应用程序都是用 C++ 编写的,因此直接提供合适的编译器套件也是合理的。 This is my thought modell, does not need to match reality.这是我的想法模型,不需要与现实相匹配。

Thanks for your help.谢谢你的帮助。

Since the kernel of Windows and the Windows API are written in C由于 Windows 的内核和 Windows API 是用 C 编写的

Microsoft doesn't ship a compiler, or the required Windows SDK headers/libs (also includes a bunch of other useful development tools) for Windows in the installation. Microsoft 没有在安装中为 Windows 提供编译器或所需的Windows SDK 头文件/库(还包括一堆其他有用的开发工具)。 Microsoft Visual C++ (part of Visual Studio ) would be the equivalent "built in" choice although I am not sure if Microsoft ever specify exactly which version they use for a given Windows build and it is common to have lots of software built with different compilers/versions (including the various non-Microsoft ones). Microsoft Visual C++( Visual Studio的一部分)将是等效的“内置”选择,尽管我不确定 Microsoft 是否曾准确指定它们用于给定 Windows 构建的版本,并且通常使用不同的编译器构建大量软件/versions(包括各种非 Microsoft 版本)。

As well as the full Visual Studio package with the IDE and other tools.以及带有 IDE 和其他工具的完整 Visual Studio 包。 Microsoft provide some components separately, such as the Build Tools for Visual Studio 2019 . Microsoft 单独提供了一些组件,例如Visual Studio 2019 的构建工具

I am sure this is for many reasons like most users not being interested in compiling their own software, and Microsoft still sells Visual Studio separately to larger organisations (historically to most serious users, but "Community" edition is now pretty nonrestrictive for individuals and small business).我敢肯定这是由于许多原因,例如大多数用户对编译自己的软件不感兴趣,并且微软仍然将 Visual Studio 单独出售给较大的组织(历史上是针对最认真的用户,但“社区”版现在对个人和小型组织没有限制商业)。

Strangely enough it doesn't come with a C compiler, we need to install one, Mingw-w64 is allways my choice, you will need to add the path in environment variables (step 12), if you want to use it anywhere.奇怪的是它没有附带 C 编译器,我们需要安装一个, Mingw-w64总是我的选择,如果你想在任何地方使用它,你需要在环境变量中添加路径(第 12 步)。 You can then use the gcc command where it's more convenient like in Linux, don't forget to open a new cmd after the changes for them to take effect.然后,您可以在更方便的地方使用gcc命令,就像在 Linux 中一样,不要忘记在更改后打开一个新的 cmd 以使它们生效。

Unfortunately, Windows doesn't have the command line tools for installing/removing stuff and the great repository infrastructure we know and love from Linux.不幸的是,Windows 没有用于安装/删除内容的命令行工具以及我们从 Linux 中了解和喜爱的出色存储库基础架构。

You will need two things:您将需要两件事:

  • The command-line build tools.命令行构建工具。 These can be found on the Visual Studio Downloads page under Tools for Visual Studio -> Build Tools for Visual Studio .这些可以在Visual Studio 下载页面的Tools for Visual Studio -> Build Tools for Visual Studio下找到。 This will include the compiler ( cl.exe ) and linker ( link.exe ) for the MSVC build toolchain.这将包括 MSVC 构建工具链的编译器 ( cl.exe ) 和链接器 ( link.exe )。
  • The Windows SDK. Windows SDK。 The latest version of the SDK can currently be found here .目前可在此处找到最新版本的 SDK。 This page has a tendency to move around, but googling for Windows SDK usually gives you the right page immediately.这个页面有移动的趋势,但谷歌搜索 Windows SDK 通常会立即为您提供正确的页面。 The SDK contains all the headers and libraries required to build Windows applications and make use of the Windows native API. SDK 包含构建 Windows 应用程序和使用 Windows 本机 API 所需的所有头文件和库。 The Windows SDK contains a lot of stuff which you may or may not need. Windows SDK 包含很多您可能需要也可能不需要的东西。 You will almost certainly want to install the Windows SDK for Desktop C++ x86 Apps and Windows SDK for Desktop C++ amd64 Apps components.您几乎肯定会想要安装Windows SDK for Desktop C++ x86 AppsWindows SDK for Desktop C++ amd64 Apps组件。 Most of the other stuff should be optional, but some of it is nonetheless highly useful.大多数其他东西应该是可选的,但其中一些仍然非常有用。
  • You may want to download additional packages such as the Windows Debugger (which is an entirely different application than the Visual Studio debugger) or the Driver SDK , depending on what kind of things you want to develop.您可能需要下载其他包,例如Windows 调试器(它是与 Visual Studio 调试器完全不同的应用程序)或驱动程序 SDK ,具体取决于您要开发的内容类型。

Note that even if you don't intend to use the IDE in the end, installing the full Community Edition of Visual Studio is a far more convenient way to get a working build environment, so unless you have a really good reason not to, just go with the full package and choose to never open the IDE.请注意,即使您最终不打算使用 IDE,安装完整的 Visual Studio 社区版也是获得工作构建环境的一种更方便的方法,因此除非您有充分的理由不这样做,否则只需使用完整的软件包并选择从不打开 IDE。

The built in compilers available on Windows 10 are for VisualBasic, C#, JScript. Windows 10 上可用的内置编译器适用于 VisualBasic、C#、JScript。 To improve speed & performance of apps, " ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer. The runtime can use native images from the cache instead of using the just-in-time (JIT) compiler to compile the original assembly".为了提高应用程序的速度和性能,“ ngen.exe创建本机映像,这些文件包含已编译的特定于处理器的机器代码,并将它们安装到本地计算机上的本机映像缓存中。运行时可以使用缓存中的本机映像使用即时 (JIT) 编译器编译原始程序集”。

For low level programmers, ilasm.exe (IL Assembler) ships with Windows, which also facilitates "tool and compiler" development;对于低级程序员,ilasm.exe (IL Assembler)随 Windows 一起提供,这也有助于“工具和编译器”的开发; so you could even create your own language or build a better compiler for a current one, or "debug your code at low level and understand how .NET deals with your high level code", or "write your own compiler for a new .NET language."因此您甚至可以创建自己的语言或为当前语言构建更好的编译器,或者“在低级别调试代码并了解 .NET 如何处理您的高级代码”,或者“为新的 .NET 编写自己的编译器语。”

For web programmers, AspNetCompiler precompiles server-side ASP.NET web-applications, therefore helps application performance because end users do not encounter a delay on the first request to the application .对于 Web 程序员, AspNetCompiler预编译服务器端 ASP.NET Web 应用程序,因此有助于提高应用程序性能,因为最终用户不会遇到对应用程序的第一个请求的延迟

All Compilers & assemblers come as builtin with Windows without IDE and can be run from "the Windows Command prompt (cmd.exe)", so no extra downloads necessary;所有编译器和汇编器都内置在没有 IDE 的 Windows 中,并且可以从“Windows 命令提示符 (cmd.exe)”运行,因此无需额外下载; located in folder: C:\Windows\Microsoft.NET\Framework\vx.x.xxxxx\ .位于文件夹: C:\Windows\Microsoft.NET\Framework\vx.x.xxxxx\ 。

Note: C# is based on JScript.注意: C#基于 JScript。

Compilers:编译器:

  • vbc.exe VB.exe
  • csc.exe csc.exe
  • jsc.exe jsc程序
  • ilasm.exe伊拉斯姆.exe
  • ngen.exe ngen.exe
  • aspnet_compiler.exe aspnet_compiler.exe

Addendum :附录

If you still are looking for a C compiler to handle some C source codes you already have spent your life on, then (without downloading) you can make/ write a C compiler , in a high level language, then optimize it with a low level language.如果您仍在寻找 C 编译器来处理您已经花费了一生的 C 源代码,那么(无需下载)您可以使用高级语言制作/编写 C 编译器,然后使用低级对其进行优化语。

This guide will "introduce you to the high-level architecture, theory, and .NET Framework APIs that are required to build your own .NET compiler" in C#. 本指南将用 C# 向您介绍构建您自己的 .NET 编译器所需的高级架构、理论和 .NET Framework API。

You can to use gcc for windows.您可以在 Windows 上使用gcc For eg mingw , tdm-gcc , mingw-68 , Cygwin etc. Each of them allows you to work on c/c++ .例如mingwtdm-gccmingw-68Cygwin等。它们中的每一个都允许您在c/c++上工作。 But if you are not sure about the installation process, and don't want to do all the work by yourself, the easiest solution is to download something like dev-c++ or code-blocks .但是,如果您不确定安装过程,并且不想自己完成所有工作,最简单的解决方案是下载dev-c++code-blocks之类的东西。

cygwin: https://cygwin.com/ cygwin: https ://cygwin.com/
mingw-64: http://mingw-w64.org/doku.php mingw-64:http: //mingw-w64.org/doku.php
Downloadable file can be found here (for mingw , dev-c++ ): https://sourceforge.net/可在此处找到可下载文件(对于mingwdev-c++ ): https ://sourceforge.net/

You can also install Microsoft compiler.您还可以安装 Microsoft 编译器。 I usually do it by installing the whole visual studio.我通常通过安装整个视觉工作室来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM