Running C

This page is organized as follows:

  1. Running C on Eustis
  2. Running C on Your Own Machine
  3. Troubleshooting
  4. Advanced Topics

You should use the free GNU C compiler for this class.

Running C on Eustis

Most students will find it easiest to use their own computer system for class work. However, if you do not have your own computer, you could use the gcc compiler on eustis.eecs.ucf.edu.

You can login to your account at eustis.eecs.ucf.edu using your NID as your login. Your default password is of the form Pyymmdd, where yymmdd is your birth year, month and day.

To access Eustis, use an ssh client like putty from anywhere on campus. From off-campus, you will need a VPN connection to UCF first. For a VPN account and help, go to http://www.noc.ucf.edu/VPN/default.htm

Starting C

On Eustis, the C system is found in /usr/bin/, which should be in your PATH by default. (Thus you shouldn't have to do anything special to set this up.)

To have gcc compile and link a whole program, in file myprog.c, issue the command:

gcc myprog.c -o myprog

at the shell's prompt. This will create a file named myprog on Eustis (or a Linux machine, or MacOS), or a file named myprog.exe on a Windows machine.

To compile a file myfun.c that is part of a program (e.g., for later linking with a program), issue the command:

gcc -c myfun.c

at the shell's prompt. This will create an object file, named myfun.o.

To link together several object (.o) files, issue the command:

gcc *.o -o myprog

This will again create a file named myprog on Eustis (or a Linux machine, or MacOS), or a file named myprog.exe on a Windows machine.

Return to top

Running C on Your Own Machine

Using Code::Blocks at home

Many students prefer to run C from within an integrated development environment (IDE); an IDE includes a text editor, a compiler, and typically other programs used in development such as a debugger, help system, etc. A commonly used example is Code::Blocks, which is a free IDE for C (and C++ and Fortran).

If you have a Macintoish computer, you should be able to just install Code::Blocks from its download page and follow the installation instructions.

If you have a Windows machine, follow the sequence of installations below.

First, Install the GNU C Compiler

To use Code::Blocks, you must first install the GNU C compiler. If you are working on Linux or MacOS X or Cygwin on Windows, then you may already have it installed, or you can install it using that system's installation and package management tools; if that does not work, then see below to install one.

On Windows, the easiest way to install the GNU C Compiler is to install the MinGW, which you can obtain from https://sourceforge.net/projects/mingw/files/latest/download?source=files. The initial download gets you an "installation manager", from which you have to select at least the mingw32-base and the mingw32-gcc-g++ packages. Then from the "Installation" menu, select "Apply changes" to actually install the base (which includes gcc). After that finishes, you can then close the installer.

Installing Code::Blocks Itself

You should then download Code::Blocks itself from http://www.codeblocks.org/downloads. It is easiest to download the binary release for your machine. There are versions for Windows as well as MacOS X and Linux.

(If you are using cygwin on Windows and have gcc installed there, see the Code::Blocks wiki about using cygwin's gcc to tell Code::Blocks about cygwin's gcc compiler.)

After installation, to use Code::Blocks you would use the File menu, and create a project. See http://wiki.codeblocks.org/index.php/Creating_a_new_project for details.

Getting GCC for your Own Machine

Instead of using an integrated development environment, you can use a text editor (such as Emacs) to create files and then run the gcc compiler from the command line to compile programs and files.

The gcc compiler used for this course is available on many platforms, including Linux, MacOS X, and Windows.

Windows

You can download gcc from gcc.gnu.org.

To use gcc at the command line, you should put the full path to the directory where gcc lives in your PATH environment variable. (To set environment variables in Windows 10/XP/Vista/7, start the control panel, then click on "System", then the "Advanced" tab, then click on "Environment Variables".)

Mac OSX

For Mac OSX, you can install the LLVM compiler, which will act like gcc, and will be available to run from the command line. To do that first issue the following command from a terminal window: xcode-select --install.

Linux

For Linux, gcc is probably already installed as a package on your machine. If not, you can install gcc from https://gcc.gnu.org/mirrors.html. Be sure that the executable is in your PATH

Others

If you find more details about a system that you had trouble with, see the course staff. If you fix such a problem yourself, please let us know how you fixed the problem.

Return to top

Troubleshooting

Case Problems

C is case sensitive.

Other Problems

If you are having a problem not described above, or if the solutions listed above are not working for you, you can look at the webcourses discussions, where we often post answers to other people's questions. If none of that help then please don't hesitate to contact the course staff.

Return to top

Advanced Topics

There are a variety of other programming environments for C that are described below.

C Eclipse Plugin

If you use Eclipse, you may want to use Eclipse CDT, which turns Eclipse into an IDE for C code.

Editing C from Within Emacs

A mode for C programs is pre-installed in Emacs. This is what Gary uses in class.

Windows Keystrokes in Emacs

If you like to use the standard Windows keystrokes for cut, paste, and copy, customize Emacs to use CUA-mode by default. (This assumes that you have Emacs version 22 or later. Use the menu "Options", select "Customize Emacs", and from there the select "Top Level Customizations". then select the "Convenience" group by clicking on the "go to group" link, and then go to the Cua group, and click on the "Value Menu" for enabling this customization.

If the above doesn't work, or if you have a version of Emacs previous to 22, put the following in your emacs initialization file, ~/.emacs.el. (The lines that start with a semicolon are comments, and can be omitted.)

(if (< emacs-major-version 22)
  (progn
    ;; Make emacs more like standard windows applications in terms of
    ;; mouse selections (this is similar to pc-select).
    ;; One advantage is this is that it makes Dragon Dictate work with Emacs.
    (require 'cua)
    ;; Make the behavior of emacs on C-c, C-v, C-x, and C-z to be
    ;; just like that of be as in standard window apps, so you can use
    ;; these keys to copy, paste, and select when there is a selection
    ;; active, then uncomment the following.
    (CUA-mode t)
    ;; Make C-c leave the region active, which is what happens under Windows.
    (setq CUA-mode-keep-region-after-copy t)
  )
  ;; The same for emacs version 22 (and hopefully higher...)
  ;; but not for aquamacs, which already has it.
  (if (not (featurep 'aquamacs))
      (progn (cua-mode)
             (setq cua-enable-cua-keys t)
             (setq cua-mode-keep-region-after-copy t)
      )
  )
)

Alternatively, you can use Gary Leavens's .emacs.el file which includes the above lines and several other things. It should be saved into .emacs.el in your home directory. (On Windows you may not have a home directory yet, so pick one. You also have to set HOME in the environment; this is automatic in Unix and hence on Mac OS X, but needs to be done by hand in Windows.)

For Vi Users

If you are a vi user, you may want to use viper-mode in emacs to get the vi keystrokes and still use all the wonderful Emacs features. To do this, put the following in your .emacs.el file:

(viper-mode)

Return to top

Last modified Friday, February 24, 2017.

This web page is for COP 3223H at the University of Central Florida. The details of this course are subject to change as experience dictates. You will be informed of any changes. Please direct any comments or questions to Gary T. Leavens at Leavens@ucf.edu. Some of the policies and web pages for this course are quoted or adapted from other courses I have taught.