CS 3330: Lab 0.1 (native compilers)

This page does not represent the most current semester of this course; it is present merely as an archive.

C compilers exist for many architectures. D compilers exist for them too (we’ll use D later in the semester).

1 C compilers

1.1 Linux

C files can be compiled on any Linux system using gcc -x c filename.c, clang -x c filename.c, or llvm-gcc -x c filename.c. Most systems will have only one of these three installed; it does not matter which one you use.

1.2 Windows

On Windows the MinGW project has a version of gcc that will probably work for most (though not all) labs, though you will need to install it yourself. Microsoft’s compiler toolchain can compile C using cl.exe /Tc filename.c, but we have never tested how well it works. If you do, please report how you found it.

Alternatively, the following all attempt to create more complete POSIX-like environments for Windows:

1.3 OS X

On OS X, Xcode ships with a version of llvm-gcc (they call it just gcc). On newer versions of the OS it is located inconveniently (/Applications/Xcode.app/Contents/Developer/usr/bin/gcc in 10.7 Lion) but can be placed where you can more easily access it from the Terminal via XCode’s Preferences → Downloads → Command Line Tools → Install.

1.4 Other

If you use another OS (FreeBSD, Haiku, Irix, etc) you probably know how run a C compiler already.

2 D Compilers

We’ll use a tool I created called hcl2d this semester, which is written in the D language. Its Makefiles assume you are using the mainline dmd compiler. To obtain that compiler,

2.1 Debian-based

Debian-based Linuxes include many of the most popular distros, such as Ubuntu and Mint

  1. add the d-language repository to your system

    sudo bash -c "echo 'deb http://master.dl.sourceforge.net/project/d-apt/ d-apt main' > /etc/apt/sources.list.d/d-apt.list"
  2. tell your system to trust the d-language repository

    sudo apt-get update
    sudo apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring
  3. ask to install dmd

    sudo apt-get update
    sudo apt-get install dmd-bin

2.2 Web Systems

On c9.io or koding.com, open a terminal and run

curl -fsS https://dlang.org/install.sh | bash -s dmd

2.3 Other Systems

On almost any OS you can, go to the dlang download page and download and run the installer for your platform.

Why D? Because after learning over 70 programming languages, it is the one I most want to use if writing more than half a dozen lines, and the one whose features I most often miss when writing in other languages.

Not perfect, though. It does not have language-level discriminant unions. ☹

— Prof. Tychonievich

Copyright © 2016 by Luther Tychonievich and Charles Reiss. All rights reserved.
Last updated 2016-08-26 10:37:05