Setting Up Your Environment
If you’d like to develop your C programs on your own hardware, here’s some tips for getting your environment set up. Remember, the CS lab machines are where we grade your assignments, so you are responsible for making sure they work there.
macOS
On macOS, you’ll need either:
- XCode from the app store (this includes the C compiler and related tools)
- The command-line developer tools (run
xcode-select --install
from your terminal and follow the instructions)
To test that everything is working correctly, run ‘gcc’ or ‘clang’ in your terminal.
Windows
Development on Windows can be tricky. One way to avoid a lot of headaches is to use a virtual machine. Here’s instructions for setting up a Linux VM on Windows
If you aren’t interested in using a Linux VM, you’ll need something along the lines of Cygwin or MinGW. This will give you a (mostly) standard UNIX development tool chain on Windows. Be sure to enable the ‘Devel/gcc-core’ and ‘Devel/make’ packages to pull in gcc and related tools on Cygwin.
Linux
Linux is the least painful to set up. Many distributions already include development tools, but installing gcc with your package manager should pull in the rest of the required dependencies. The lab machines are already configured correctly for C development.
If you can’t get your own environment set up, you can always make use of the CS lab machines (either on campus or remotely – see http://www.cs.usfca.edu/support.html).
Text Editors
Many students develop their C programs with text editors such as Sublime Text, Atom, or VS Code. These are all good options. In general, you’ll have an editor window open as well as a terminal so that you can compile, test, and edit your code. Something like this:
You may also want to get familiar with a terminal-based editor such as vim or emacs. Lots of tutorials are available online, and learning a terminal editor can be extremely useful.
There are also plenty of IDEs that work well with C…
CLion
Once you’ve installed the dependencies above, you should be good to go. On Windows, just point CLion to your installation of Cygwin.
Eclipse
When using Eclipse, be aware of the following:
- Use the gcc available for your platform, not the ‘Cross gcc’ option when creating a project.
- You will need to build your program (
Project > Build
) before you can run it.
Command Line
To make sure you have a compiler installed and configured correctly, just run ‘gcc’ at the command line. You can compile your program with
gcc prog_name.c
And then run with
./a.out
You can also specify a name for your executable (a.out is just the default), and show all compiler warning messages. ‘-Wall’ turns on all warnings, and ‘-o’ specifies the output file:
gcc -Wall prog_name.c -o my_program
./my_program