How to Compile a C Program
This wikiHow 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. Go to https://cygwin.com/install.html. Cygwin is a free Windows tool that...
Method 1 of 3:
Using Cygwin for Windows
-
How to Compile a C Program Picture 1
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. -
How to Compile a C Program Picture 2
Click the setup-x86.exe file for your Windows version. If you're using the 64-bit version of Windows, download setup-x86_64.exe. If you have the 32-bit version, download setup-x86.exe. -
How to Compile a C Program Picture 3
Run the installer. Double-click the downloaded file to open the setup wizard. Downloaded files usually save to the Downloads folder.- If prompted to give permission for the installer to run, click Yes.
-
How to Compile a C Program Picture 4
Click Next on the first screen. -
How to Compile a C Program Picture 5
Select Install from Internet and click Next. -
How to Compile a C Program Picture 6
Choose where to install the app and click Next. -
How to Compile a C Program Picture 7
Select local package directory and click Next. This is where packages you download will be saved. -
How to Compile a C Program Picture 8
Choose your internet settings and click Next. The installer will connect to the internet and then display a list of download sites. -
How to Compile a C Program Picture 9
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.
-
How to Compile a C Program Picture 10
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.
-
How to Compile a C Program Picture 11
Click Next. It's at the bottom-right corner. A confirmation message will appear. -
How to Compile a C Program Picture 12
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. -
How to Compile a C Program Picture 13
Open Cygwin. It'll be in the Start menu (called either Cygwin64 or Cygwin32, depending on your version). -
How to Compile a C Program Picture 14
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 Documents folder, you would type cd c:Users(yourusername)Documents and press ↵ Enter.[1]- A quick way to find the full path to your file: Press ⊞ Win+E 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.
-
How to Compile a C Program Picture 15
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.[2] Your code is now compiled.
Method 2 of 3:
Using Visual Studio for Windows
-
How to Compile a C Program Picture 16
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 Visual Studio 2017 folder, then click Developer Command Prompt for VS 2017 (or your version number).[3] -
How to Compile a C Program Picture 17
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 Documents 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.
-
How to Compile a C Program Picture 18
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.
Method 3 of 3:
Using Xcode for macOS
-
How to Compile a C Program Picture 19
Install Xcode on your Mac.[4]- Mavericks (10.9) and later: Open the App Store
How to Compile a C Program Picture 20
- 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."
- Mavericks (10.9) and later: Open the App Store
-
How to Compile a C Program Picture 21
Open Xcode. Now that it's installed, you'll find it in the Applications folder. -
How to Compile a C Program Picture 22
Click the File and select Open. -
How to Compile a C Program Picture 23
Select your code file and click Open. The contents of your code will appear.[5] -
How to Compile a C Program Picture 24
Click the Product menu. It's at the top of the screen. -
How to Compile a C Program Picture 25
Click Archive. This compiles and links your C code. When it's ready to be exported, a window containing options will appear. -
How to Compile a C Program Picture 26
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.
5 ★ | 2 Vote
You should read it
- How to Hide a File or Folder from Search Results in Microsoft Windows
- How to Zip Folder on Windows
- What is a folder The concept of a file (File) and a folder (Folder) in a computer
- How to Lock a Folder on Windows
- How to Zip a File in Windows
- How to Set Password for Folder and File in Windows
- How to save files to multiple folders on the web browser
- How to Extract a Gz File
- Open the file, open the folder with a mouse click
- What is the FOUND,000 folder and the file FILE0000.CHK on Windows?
- How to Compile CPP File to EXE
- How to Create JAR File