How to Compile a C Program

Method 1 of 3:

Using Cygwin for Windows

  1. 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.
  2. 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.
  3. 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.
    1. If prompted to give permission for the installer to run, click Yes.
  4. How to Compile a C Program Picture 4
    Click Next on the first screen.
  5. How to Compile a C Program Picture 5
    Select Install from Internet and click Next.
  6. How to Compile a C Program Picture 6
    Choose where to install the app and click Next.
  7. How to Compile a C Program Picture 7
    Select local package directory and click Next. This is where packages you download will be saved.
  8. 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.
  9. 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.
    1. If there's a problem with one site, try another on the list.
  10. How to Compile a C Program Picture 10
    Select packages to install. Follow these steps to ensure the C compiler is installed:
    1. Click the + next to "Devel" to expand the options.
    2. Scroll down and click the down-arrow next to gcc core.
    3. Click the most recent (highest) version number.
  11. How to Compile a C Program Picture 11
    Click Next. It's at the bottom-right corner. A confirmation message will appear.
  12. 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.
  13. 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).
  14. 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]
    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.
  15. 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

  1. 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]
  2. 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
    1. Your code must be in a file that ends with the ".c" extension to use this method.
  3. 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

  1. How to Compile a C Program Picture 19
    Install Xcode on your Mac.[4]
    1. Mavericks (10.9) and later: Open the App Store
      How to Compile a C Program Picture 20
      and search for xcode. Click GET to install, and follow any on-screen instructions.
    2. 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."
  2. How to Compile a C Program Picture 21
    Open Xcode. Now that it's installed, you'll find it in the Applications folder.
  3. How to Compile a C Program Picture 22
    Click the File and select Open.
  4. How to Compile a C Program Picture 23
    Select your code file and click Open. The contents of your code will appear.[5]
  5. How to Compile a C Program Picture 24
    Click the Product menu. It's at the top of the screen.
  6. 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.
  7. 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

May be interested

  • C ++ editor onlineC ++ editor online
    online cplusplus editor has a very fast execution time, detects errors related to the syntax as soon as you type the code with a red x right on the error code, color the code ... and run as soon as you code by clicking go to execute.
  • Top website to write and compile online code bestTop website to write and compile online code best
    the compiler, is a computer program that translates a sequence of statements written in a programming language into an equivalent program but in the form of a new computer language.
  • How to End a Program on a PCHow to End a Program on a PC
    have you ever had a program hang and waiting for the computer to sort the problem out was not an option? this puts in effect the immediate termination of almost any irritating, hanging, unresponsive program on your pc. kill ===windows===
  • How to Exit out of a Frozen Computer ProgramHow to Exit out of a Frozen Computer Program
    sometimes a program will just not respond to any commands and will need to be forcibly shut down. there are a few different ways to do this, depending on the severity of the broken program, and your operating system. hold down + + . this...
  • HTML editor onlineHTML editor online
    online html editor supports html5, when you type the opening tag automatically generates a closed tag, can detect errors related to the syntax when you are editing with the square icon with the x mark right on the error code line.
  • How to uninstall Windows Insider Program Windows 10How to uninstall Windows Insider Program Windows 10
    windows 10 windows insider program is a program registered with those who want to experience before the preview will be upgraded to the full version before it is released.
  • Learn about the Program files folder in WindowsLearn about the Program files folder in Windows
    program files is a folder first found in microsoft windows 95 and included in all later versions of microsoft windows, for storing software programs installed on a computer.
  • What is a sandbox and how does it sandbox a program?What is a sandbox and how does it sandbox a program?
    many browsers today are designed to automatically run in their own sandbox without user settings.
  • Instructions for uninstalling Windows Insider ProgramInstructions for uninstalling Windows Insider Program
    the windows insider program allows you to experience new features early, but it comes with the risk of system errors and instability. if you no longer want to use this test build, exiting the program is necessary to ensure performance and stability of your computer.
  • Microsoft rewarded $ 250,000 in a new bug-finding programMicrosoft rewarded $ 250,000 in a new bug-finding program
    microsoft finally launched a bug bounty program for security researchers and bug hunters, and then reported bugs on the latest windows operating systems and software.