Thes are the main components in the CIS 341 tool chain:
- LLVM compiler version 5.0.1
- llc - the C compiler and assembler
- OCaml compiler and tools:
- ocamlc - the ocaml compiler (version 4.04.0 or later)
- ocamlbuild - an ocaml-compatible build system
- menhir - an LR1 parser generator
- Code editors / Development Environments:
- (Optional) a version control system:
We recommend that you use a version control system to periodically back up your progress on the course projects.
For help with tool chain configuration, please post to Piazza.
The compiler we build will generate x86 assembly code, so if you want to run the programs natively, you must develop on a machine with and Intel or AMD processor.
You can do all of your development on Eniac, and we will be testing your projects there. It provides a linux environment, but the default installations of llc and ocamlc are out of date. The course account ~cis341/bin directory contains up-to-date versions of the course software.
When working on eniac, make sure that /home1/c/cis341/bin is in your PATH environment variable before /usr/bin. (You will need to edit your .login or .bashrc, etc., as appropriate to ensure that this is the case.
Check that your set-up on Eniac is correct like this:
> which ocaml /home1/c/cis341/bin/ocaml > ocaml Objective Caml version 4.04.0 #
OS X Only Setup
First, make sure that you have a c compiler and command line tools: Install Xcode via the App Store. Or install just the "Command Line Tools", which should be available through the Apple Developers Download Site (login with your Apple ID required).
Next, follow the instructions below (following the OS X specific parts).
On Linux and OS X (after the OS X only setup)
LLVM toolsFollow the directions here: http://llvm.org/docs/GettingStarted.html . The short version is:
- Make sure you have a recent version of cmake (available from cmake.org. Most of the other LLVM dependencies (gcc, svn, gunzip, gnu make, python, zlib), should be standard.
- Get a copy of the LLVM source code either by:
- Downloading the source code llvm-5.0.1.src.tar.xz
and then extracting the zipped tar file:
> gunzip llvm-5.01.src.tar.xz > tar -xvf llvm-5.01.src.tar
- or, using subversion:
svn co http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_501/final llvm-5.0.1
- Downloading the source code llvm-5.0.1.src.tar.xz and then extracting the zipped tar file:
- Compile and install the llvm tools:
> mkdir llvm-build -- create a directory parallel to /llvm > cd llvm-build > cmake -G "Unix Makefiles" ../llvm-5.0.1.src > make -j2 -- drop -j2 flag if not on multiprocessor / takes a while! > make install
OCaml and its tools
We recommend using OPAM. Follow the installation istructions from Real World OCaml.
Once opam is installed, upgrade to ocaml version 4.04.0 and then install ocamlbuild and menhir like this:
> opam install ocamlbuild > opam install menhir
Using Microsoft Windows
You should install following software before installing OCaml (and Eclipse):
- Visual Studio If you don't have it already, you should use your free MSDNAA access to download a copy of Visual Studio. The installation needs to include at least the VC and Microsoft SDKs components.
- Follow the installation instructions at www.cygwin.com.
- Select packages. Besides the default packages, we need two more
- After search 'make', click on '+' to extend the categories tree: the root node is "All", and the child node is "Devel". The package ``make: The GNU version of the 'make' utility''
- After search 'ncurses', click on '+' to extend the categories tree: the root node is "All", and the child node is "Utils". Then on the package ``ncurses: Utilities for terminal handling''.
- Click Next, ..., Then finish.
Edit "Path" variable in the system variables, append the appropriate paths string to its variable value, e.g.:
;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin;C:\Work\Tools\cygwin\bin;C:\Program Files (x86)\flexdll;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin
Note that C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin must be before C:\Work\Tools\cygwin\bin to overwrite executables such as link.exe from Cygwin, and there is a ";" in the beginning of the string.
Edit "Lib" variable in the system variables (New a "Lib" variable if there does not exist one), append the following string to its variable value:
;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib
- You probably need to add the Cygwin support.
Eclipse and OcaIDE Setup
You may skip "Install OCaml" and "Install Eclipse" if working on SEAS lab machines.
- To run Eclipse, a Java Runtime Environment (JRE) must be installed. You can check if Java is installed on your machine.
- Visit the Eclipse download page.
Click on the link for your platform on the right side of the screen
and install it by simply unpacking the downloaded file onto your desktop.
- Note: The 64-bit Windows version of Eclipse may not be able to locate Java installations. If this happens, use the 32-bit Windows version instead.
- Launch Eclipse. The first time you run Eclipse, you need to choose a workspace (a folder that stores your projects). Use the default location that Eclipse suggests, or choose your own location.
- In Eclipse, click Help » Install New Software...
In Work with, enter
http://www.algo-prog.info/ocaidethen click Add, OK.
- Check OcaIDE and click Next, Next, I accept, Finish to accept the license and install the software. Eclipse will prompt you to accept unsigned code.
- Click Restart Now. After Eclipse restarts, close the Welcome tab and click Window » Open Perspective » Other... » OCaml.
Go to Window » Preferences (Mac OS X users, go to Eclipse » Preferences).
Click on "+" or "▶" next to OcaIDE to expand the tree and then click on Paths.
If all the paths in this panel (except for possibly make and omake) are
already filled in, then continue to the next step.
Otherwise, click Browse next to OCaml Binaries Directory and choose the "bin" directory
inside your OCaml installation directory (for example, C:\Program Files\ObjectiveCaml\bin).
Then press Apply. Eclipse should fill in additional path values for you (ocaml, ocamlc, etc).
- Under Other tools » OCaml lib path, click Browse and choose the "lib" directory inside your ObjectiveCaml installation directory. Press OK to close the dialog.
- Near the top right of Eclipse, you should see an OCaml button and Java button, with the Ocaml button selected. If you only see the Java button, click the button to the left which looks like a window with a yellow "+" sign, and then double click on "OCaml". Now you are in OCaml mode.
Click the "Ocaml Toplevel" tab at the bottom of the
workspace. You should see the OCaml output display:
OCaml version 4.01.0 #Type into the prompt (do not type next to the #; the prompt box is at the bottom of the tab):
print_endline "hello world";;You should see the output:
hello world - : unit = ()
Importing a project into EclipseThese instructions show how to import a project into Eclipse. The example shown is for hw1.zip -- other projects must be configured similarly.
First, download the project source and import it into Eclipse as a new project:
- Download the hw1.zip archive to some folder on your machine.
> mkdir ~/tmp > cd ~/tmp > wget http://www.cis.upenn.edu/~cis341/15sp/hw/project1/project1.zip
- Launch Eclipse and make sure that you are running in the OCaml perspective.
- Create a new Eclipse project: File » New » OCaml project
Note: Unlike CIS 120, CIS 341 uses the OCamlbuild project option not the OCaml Managed option.Name the project hw1
- Import the project files:
- Select hw1 in the Navigator panel.
- Do: File » Import
- Pick "General / Archive File" as the "import source" and click Next
- Browse to the hw1.zip file as the "from archive file" and then select the "/" directory and its files when they appear in the panel
- "into folder" should already be set to hw1
- Click Finish
- Configure the project to produce the right executables:
- Make sure the project is still selected in the Navigator panel.
- Open the Project » Properties dialog.
- Select the Project pane (choose it from the left column)
- In the Targets box add main.byte,main.native (main.ml is the top-level executable; see the details in comments of that file)
- Close the dialog by clicking OK. At this point Eclipse should build the project, creating a _build directory and the main.byte and main.native files should appear in the Navigator panel. (Note that every time you save a project file, Eclipse will by default try to rebuild your project; you can also rebuild manually from the Build menu.)
- Create a "Run Configuration" for this project (only needs to be
- Open the Run » Configurations... panel. Select "Ocaml Exectuable" and then click on the 'New' button icon (a little white rectancle with a yellow +).
- Name the configuration something like "Run Hw1"
- Enter hw1 for the project name
- Browse to the main.native file that was created when you built the project.
- Enter the flag --test in the "command line arguments" field -- this tells the main harness to run in test mode, most of which will fail until you complete the project.
- Click Apply and then Run
If all was successful, Eclipse should pop up a Console window with the output of running the main program's test cases.
- If Eclipse reports "ocamlbuild" depends on Cygwin, then you need to install Cygwin's make.exe.
- If the compilation failed because OCaml cannot find tput.exe, you need to install Cygwin's ncurses package.
- If it failed to find ml.exe, advapi32.lib, msvcrt.lib, or mspdb100.dll, please check that the environment variables Path and Lib are set correctly for Visual Studio.
- If it failed to find flexlink.exe, you need to install flexdll.
- If native linkage fails, please check that Cygwin's path overwrites Visual Studio's path.
Subversion + Eclipse
Even if you're working alone, it's still useful to set up a source control system. Subversion works well and integrates nicely with Eclipse. If you're going to be working with a partner, contact CETS about setting up a UNIX group on ENIAC so that you can share a code repository. As the projects become more complicated, having controlled sharing of the source code may save you many headaches. If you do set up a repository, try to avoid checking in binary files.
Subclipse Installation and Configuration
- Follow the installation instructions.
- Browse repositories on SVN.
- Window » Open Perspective » SVN.
- Right click on the SVN repository view » New » Input SVN URL.
- Checkin a project into SVN.
- Right click on the project name, select Team » Share project
- Select a repository or Create one » Choose a directory to checkin.
- Create a project from SVN.
- File » New » Other » SVN » Checkout projects from SVN.
- Select "Create a new repository location" and then input the URL.
- Select the directory to checkout from the repository tree, and choose "Checkout as a new project".
- Then follow the new project wizard to create an OCaml (ocamlbuild) project.
- Please refer to Help » Help Contents » Subclipse for other features.