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.
windows - How to compile a C program? - Stack Overflow
Compiling C-code from the Command Prompt in Windows? - Stack Overflow
gcc - How do I compile a C/C++ program through windows command prompt? - Stack Overflow
How to run C in windows
Videos
You may need to install either cygwin or mingw, which are UNIX-like environments for Windows.
- http://www.mingw.org/
- http://www.cygwin.com/
When downloading/installing either cygwin or mingw, you will have the option of downloading and installing some optional features; you will need the following:
- gcc (try version 2.x first, not 3.x)
- binutils
- GNU make (or gmake)
If it requires gcc and you want it to run on Windows, you could download Cygwin.
That's basically an emulator for GNU/Linux type stuff for Windows. It works with an emulation DLL.
http://www.cygwin.com/
You do this:
Copycl app.c
Here's a complete transcript, including setting up the environment for Visual Studio 2005 (change "8" to "9.0" for Visual Studio 2008).
CopyC:\src\tests>"\Program Files (x86)\Microsoft Visual Studio 8\vc\bin\vcvars32.bat"
Setting environment for using Microsoft Visual Studio 2005 x86 tools.
C:\src\tests>type app.c
#include <stdio.h>
int main(void)
{
printf("Hello world!\n");
return 0;
}
C:\src\tests>cl app.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
app.c
Microsoft (R) Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.
/out:app.exe
app.obj
C:\src\tests>app
Hello world!
MinGW provides a popular command-line GCC compiler for Windows.
if you have codeblocks installed with mingw as the gcc compiler then follow these steps
- Right click on my computer -> go to properties -> advance system settings
- Then make an environment variable named PATH and paste the complete url like program file (x86)/codeblocks/mingw/bin.
- now open cmd
- go to the directory where your program is saved.
- type gcc program_name.c -o program_name.exe to compile the program.
- run the program by typing program_name
Please read Compile Programs with MinGW -- A Guide for New Users.
To make gcc produce assembler code, use -S option:
-S Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified. By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with .s. Input files that don't require compilation are ignored.
Good luck!