This minHour teaches you how to compile your C program in Windows and macOS. If you're using Linux, check out How to Compile a C Program Using the GNU Compiler.
Using Cygwin for Windows
Go to https://cygwin.com/install.html.
Cygwin is a free Windows tool that allows you to use the GCC C compiler from a Unix command line.
Click the setup-x86.exe file for your Windows version.
If you’re using the 64-bit version of Windows, download . If you have the 32-bit version, download .
Run the installer.
Double-click the downloaded file to open the setup wizard. Downloaded files usually save to the folder.
- If prompted to give permission for the installer to run, click Yes.
Click Next on the first screen.
Select Install from Internet and click Next.
Choose where to install the app and click Next.
Select local package directory and click Next.
This is where packages you download will be saved.
Choose your internet settings and click Next.
The installer will connect to the internet and then display a list of download sites.
Select a download site and click Next.
These sites all host the same files. This downloads the installation files to your computer.
- If there’s a problem with one site, try another on the list.
Select packages to install.
Follow these steps to ensure the C compiler is installed:
- Click the + next to “Devel” to expand the options.
- Scroll down and click the down-arrow next to gcc core.
- Click the most recent (highest) version number.
Click Next.
It’s at the bottom-right corner. A confirmation message will appear.
Click Next to start the installation.
Cygwin will now download all selected tools and install them on your computer. Follow the on-screen instructions to complete the installation.
Open Cygwin.
It’ll be in the Start menu (called either or , depending on your version).
Use the cd command to navigate to the location of your C code.
You’re looking for the file you coded with “.c” at the end. For example, if your code is located in your folder, you would type cd c:Users(yourusername)Documents and press ↵ Enter.
- A quick way to find the full path to your file: Press to open the File Explorer, go to the folder that contains your file, click the file once to select it, then click Copy Path at the top of the screen. Now you can right-click the Cygwin command line and select Paste.
Type gcc yourcode.c –o yourcode.exe and press ↵ Enter.
Replace “yourcode.c” with the name of the file, and “yourcode.exe” with the name of your program. Your code is now compiled.
Using Visual Studio for Windows
Open Developer Command Prompt for VS.
This app is separate than the main Visual Studio app. To find it, click the Start menu, expand the folder, then click (or your version number).
Use the cd command to navigate to the location of your C code.
You’re looking for the file you coded with “.c” at the end. For example, if your code is located in your folder, you would type cd c:Users(yourusername)Documents and press ↵ Enter
- Your code must be in a file that ends with the “.c” extension to use this method.
Type cl yourcode.c and press ↵ Enter.
Replace “yourcode.c” with the name of your file. This creates a file called yourcode.exe from your code file.
Using Xcode for macOS
Install Xcode on your Mac.
- Mavericks (10.9) and later: Open the App Store and search for xcode. Click GET to install, and follow any on-screen instructions.
- Lion and Mountain Lion (10.7 and 10.8): Follow the instructions for Mavericks and later. Once installed, open the app (it’s in the Applications folder), click the File menu and then Preferences. Click the Downloads tab, then click Install next to “Command Line Tools.”
Open Xcode.
Now that it’s installed, you’ll find it in the Applications folder.
Click the File and select Open.
Select your code file and click Open.
The contents of your code will appear.
Click the Product menu.
It’s at the top of the screen.
Click Archive.
This compiles and links your C code. When it’s ready to be exported, a window containing options will appear.
Select Export as an Xcode Archive and click Next.
Xcode will create a new folder (inside the folder where your code is saved) and place the executable file inside.