Skip to main content
X

Explore your training options in 10 minutes

C: How To Setup Your C Compiler

Christina Kopecky - January 22, 2021


Let’s take a look at how to get started with learning C. C, unlike JavaScript, is a low-level language that needs to be compiled in advance, prior to execution. You need to download a compiler to get started, if you would like to work with C on your machine. To do this, you need to know which platform you will be working on.

Use the Hello World in C tutorial from Career Karma to test your install to see if your setup runs correctly.

MacOS

Two Options: Command Line Tools or Full XCode Install

Command Line Tools

  1. Open Terminal
  2. Run xcode-select --install
    • This prevents a full xcode install — which is not needed for simple C applications.
  3. Install developer command line tools when prompted.

Full XCode Install

  1. Open AppStore and Install XCode
  2. Open Terminal
  3. After install is complete, run gcc
  4. Install developer command line tools when prompted.

Windows

Two Options: Windows Subsystem for Linux or Cygwin

Windows Subsystem for Linux (WSL)

Note: Only available for Windows 10 and higher

Get offers and scholarships from top coding schools illustration

Find Your Bootcamp Match

  • Career Karma matches you with top tech bootcamps
  • Access exclusive scholarships and prep courses










By continuing you agree to our Terms of Service and Privacy Policy , and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.

The Windows Subsystem for Linux is basically a minified Linux that can run in your Windows environment without the need for a traditional virtual machine.

  1. Go to the Microsoft Store and install WSL – Ubuntu is a solid choice when it comes to distributions, but you can choose whichever you’d like.
  2. Check your Windows build number. The latest version of Ubuntu requires >=Windows 10 build 16237.
    • To check Windows build number, hit Win Key + R , type winver and enter. A window should pop up with the information (the build number will be in parentheses next to version number). You can also use the search Cortana feature and type winver . Click the first search item that comes up where it prompts to run the command.
    • If pre-16237, you’ll need to turn on developer mode by going to: Settings > Update & Security > For Developers and select “Developer mode”.
  3. Run bash from the command prompt or start menu.
  4. Run sudo apt install build-essential to install GCC. If you get an error, try sudo apt-get update && sudo apt-get install  build-essential
  5. To get to your Windows drive from Bash, type: cd /mnt/c/Users/<YourUserName>
    • Note: There is no supported way to access your WSL drive from Windows command prompt.
  6. Run VS Code as normal.
    • Note: To get VSCode’s integrated terminal to use WSL bash, add the following to your VS Code user settings:
"terminal.integrated.shell.windows": 
"C:\\Windows\\System32\\bash.exe"

Cygwin

Note: Prior to Windows 10. Any programs you compile with Cygwin will only run within Cygwin.

  1. Install Cygwin
  2. Launch Windows command prompt
  3. Install the necessary packages by running the Cygwin Setup utility.
    setup-x86_64.exe -q -P wget -P gcc-g++ -P make -P diffutils -P libmpfr-devel -P libgmp-devel -P libmpc-devel
  4. Launch Cygwin-Terminal from its icon

To get VSCode’s integrated terminal to use Cygwin bash, add the following to your VS Code user settings:

"terminal.integrated.shell.windows": "C:\\cygwin\\bin\\bash.exe",
"terminal.integrated.env.windows" {"CHERE_INVOKING": "1"},
"terminal.integrated.shellArgs.windows": ["-l"]

Use Your Compiler

Use your Bash shell or Terminal to cd into the folder/directory where your file is.

Compile it with: gcc -Wall -Wextra -o <NameOfFile> <NameOfFile.c> -Wall and – Wextra have to do with listing warnings in your terminal when you compile

Run it with: ./<NameOfFile>

Conclusion

In this article we’ve looked at two ways to install and run a compiler on your machine.

About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.

What's Next?

Christina Kopecky

About the author: Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.

Skip to main content