You can use GCC on Windows by downloading MingW (discontinued) or its successor Mingw-w64.
Answer from Ben Hoffstein on Stack OverflowDoes Windows have an integrated built-in C/C++ compiler package? - Stack Overflow
What Windows compiler am I supposed to be using as a beginner?
windows - Is there a single official C compiler, and how do I install it? - Stack Overflow
good c/c++ compiler for windows - Stack Overflow
Can I use a C Compiler for Windows on Windows 11?
Do I need a different C Compiler for C++ on Windows?
How do I install a C Compiler for Windows using MinGW?
I've been learning C and playing around with it for a couple of months already.
I'm following CS50 course and first half of the course is almost entirely in C.
That being said, I only used their online codespaces so far, - and for my own personal practice, I used online complilers such as https://www.programiz.com/c-programming/online-compiler/
and https://www.onlinegdb.com/online_c_compiler .
This allowed me to focus on coding and not worry about compiling. I've made some stuff already, entirely using these tools.
However, now arrives the time that I need my own compiler on local machine.
The main reason is that I want to start practicing working with files on my own hard disk, and also using libraries outside of what these tools offer, such as conio.h.
I already tried to google how to set-up a compiler in Windows, but I've bumped into many hoops and obstacles and it's not (at least for me) as straightforward as it might seem.
So I'm asking you for help to set up my own coding environment for C in Windows, where I could compile the files (ideally with make too, and not just clang), where I could include external libraries, where I could work with files on my own HDD, etc... And ideally, where I could even turn these files into classical .exe files.
Thanks!
EDIT: Resolved:
Installing Visual Studio 2022 Community with included tools for C++, and then running Developer Command Prompt allowed me to compile C files by using command: cl filename.c which returns exe file, filename.exe . This exe file can be started by simply executing filename in command prompt or even from Windows by simply double clicking on its icon, like any other file. Thanks for all the responses, especially to RidderHaddock and _mutaz_ who gave me best directions.
Since the kernel of Windows and the Windows API are written in 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 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).
As well as the full Visual Studio package with the IDE and other tools. Microsoft provide some components separately, such as the Build Tools for 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).
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. This will include the compiler (
cl.exe) and linker (link.exe) for the MSVC build toolchain. - The Windows SDK. The latest version of the SDK can currently be found here. This page has a tendency to move around, but googling for Windows SDK usually gives you the right page immediately. The SDK contains all the headers and libraries required to build Windows applications and make use of the Windows native API. The Windows SDK contains a lot of stuff which you may or may not need. You will almost certainly want to install the
Windows SDK for Desktop C++ x86 AppsandWindows SDK for Desktop C++ amd64 Appscomponents. 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.
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.
I keep finding so many conflicting answers online and I just want an easy to use (and install too, preferably) and "accurate" compiler, preferably lightweight and one that I can build actual software with it and won't need to grow out of it too (unlike onlinedgb).
"Is there a single official C compiler, and how do I install it?"
No, there is no compiler provided by the C standard and thus no way to install it.
You have to use a third-party compiler. The most common for Linux and macOS are called GCC (GNU Compiler Collection) and Clang.
Since you ask for Windows, there are several C compilers available.
Take a look at the answers and comments to this question of mine a while ago:
Has Windows an integrated built-in C/C++ compiler package?
There you can find the at least many options.
The way to install you can find in the respective documentations and isn't object to be defined here as this would explode the frame.
My personal recommendation is GCC with the MingW_64 package. How you install it, you can find, as said, in the documentation.
Is there a single official C compiler? No.
Are you sure that you insist on the "official" one (which is not even clearly defined as the other comment pointed out)?
In your situation I would look for a "convenient" installation.
This more or less leads to the answer to "How to install it?"
The selection and indirectly the way to install it, is most wisely based on asking your friends/colleagues/fellows, because you will have questions and they are primarily best answered by any human you can directly ask. StackOverflow is only second place.
If that does not help you selecting one, I recommend to use yoru favorite search engine on "install gcc". In mine, the 10th result is my favorite.
Maybe go one step further towards "convenient" and search for "free IDE C" my favorite is the 6th result.
But of course this is not to tell you my favorite in a hidden way. You just look at the results, check the first few out and decide based on what you like best.
Usually on windows the mentality is a bit different. Rather than worrying about a compiler, you worry about getting a good IDE that does all that for you.
As a result, Visual Studio is the best option.
Visual Studio Express
MingW (which is gcc IIRC)
Cygwin with the proper packages.
I'm looking for a C compiler or compiler suite that is :
-
free, preferably FLOSS.
-
modern : C17, and not just the "required features like MSVC. Say, like supporting
<threads.h>and the like. -
able to target ideally >= XP but >= 7 is crucial.
-
good at generating reasonably efficient (memory, CPU, binary size) code.
-
allows access to Microsoft's POSIX counterparts. Say, like RtlGenRandom or the like.
-
reasonably straightforward to install and set up.
I don't really need an IDE, so if a compiler does not come with one, it doesn't matter; if it does, that's alright.
It'd be nice if the compiler has some static-linking features too.
Those more experienced with developing modern C for/in Windows than me can probably answer this trivially, but I've been searching for hours to little end.
I used to rely on Visual Studio's compiler, but they really only care for C++ and used to barely even support most of C99. Their C11/17 "support" comes in 2021, and is still not fully released yet.
Also, as the post hyperlinked there also mentions :
Windows SDK releases correspond with Windows OS releases. C11 and C17 support requires Windows SDK 10.0.20348.0 (version 2104) or later.
This makes it seem like (correct me if I'm wrong), but C11/17 support for MSVC binaries is limited to the latest Windows 10 . Ugh.
As for MinGW-w64, It seems (correct me if I'm wrong), that Windows' API calls (say, rand_s()) are not possible.
Clang on Windows seems to rely on Visual Studio's linker, kind of like it uses GCC's ld on Linux, and there's little to no information about it.