Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download and install Microsoft's Visual Studio C/C++ compiler without Visual Studio

I'm trying to run c code on my windows. (I had been running it so far on repl.it). But it is proving harder than it is supposed to be. MinGW is not installing due to some reason. And I've spent a lot of time trying to run it some other way. From my research, I think the best way to go about it is to download Visual Studio, but I have a low-end PC and I don't think I should install Visual Studio. Can I, somehow, only install the C/C++ compiler that comes with it without installing Visual Studio itself.

If it helps, I usually run my (python) code in atom, but also have Visual Studio Code installed on my machine.

I apologize if my question is stupid, I am a self-taught programmer who learned to code from MIT's 6.00.1x and 6.00.2x and am currently trying to learn C from 'The C Programming Language' by Kernighan and Ritchie. I've never formally studied computer science.

like image 343
Huzaifa Avatar asked Mar 03 '18 21:03

Huzaifa


People also ask

Do you need Visual Studio for C?

Visual Studio comes with its own C compiler, which is actually the C++ compiler. Just use the . c file extension to save your source code. You don't have to be using the IDE to compile C.

How do I install Microsoft Visual C++ compiler?

You can install the C/C++ extension by searching for 'c++' in the Extensions view (Ctrl+Shift+X). Install the Microsoft Visual C++ (MSVC) compiler toolset. If you have a recent version of Visual Studio, open the Visual Studio Installer from the Windows Start menu and verify that the C++ workload is checked.


Video Answer


2 Answers

What you want is called the "Windows SDK", wich contains everything you need to build applications on windows, except the IDE (Visual Studio).

It comes with all necessary libraries, header files, a compiler, nmake et cetera, and a handy shortcut for a preconfigured cmd.exe that puts all of these tools in your PATH. If you know what you are doing, this is what you want to use.

What version of the SDK you want depends on the system you are compiling on, but you will find all of them on the microsoft website. For windows 10 for example, the SDK can be found here: https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk

Be aware though, that the windows compiler cl.exe can be a bit tricky at times, and nmake is not what you expect when you only learned GNUmake. If you are only starting out learning C, then I would not recommend using the SDK for the reasons given in the comments to your question. However, if all you want is compile on windows, without having to drag 20+ Gigabytes of IDE around, then the SDK is an option to consider.

(We are using virtual machines with a preinstalled windows SDK quite successfully in lectures and exercises.)

UPDATE:

I have been made aware that as of windows 8 the SDK no longer contains the build tools for C++ based applications. These are now only contained in a Visual Studio installation.

like image 151
Andreas Grapentin Avatar answered Oct 18 '22 10:10

Andreas Grapentin


You can download the compiler and related stuff as part of the Visual Studio Build Tools. The 2017 version is here:

https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017

like image 37
Joe Avatar answered Oct 18 '22 08:10

Joe