CIS 120: Programming Languages and Techniques I

Creating OCaml homework/lab projects in Eclipse

You should already have OCaml, Eclipse and OcaIDE set up. If this is not the case, follow our setup instructions. The lab computers are all set except for switching to the OCaml perspective in Eclipse. (Window » Open Perspective » Other... » O'Caml.)

  1. Download the zip for the homework or lab, and extract the files.
  2. In OcaIDE within Eclipse, click File » New » OCaml Managed Project. Enter the homework/lab name (e.g. Lab01) for "project name" and click Finish.
  3. Right click on the newly created project folder and click Import... » General » File System » Next.
  4. Click Browse (next to the From directory field), select the temporary folder containing the extracted files from the zip (e.g., lab01_temp), and click OK.
  5. Click Select All then Finish. Expand the project folder in Eclipse to see the files that were copied into your workspace as well as some OcaIDE-generated ones which are outlined in red.
  6. Delete the temporary extract folder, otherwise you might accidentally upload these files instead of the edited files in your Eclipse workspace.

Running your homework or lab in Eclipse

In order to run (and test) your homework or lab, you must configure Eclipse to create an executable.

  1. Right click on the project folder and select Properties.
  2. Click Ocaml Project.
  3. Under "Make executable for:" check off the file that you want to run (e.g., Leave "Compilation mode" as byte-code. Press Apply and OK to close the dialog.
  4. In your project, you should now see a new item (fileName.exe). If not, make sure your code compiles without error.
  5. To run the executable, right click on fileName.exe in Eclipse and select Run As » OCaml Executable. The output of the program should appear in the Console tab. If nothing appears in the Console, you may also try Run As » OCaml Toplevel. A new OCaml Toplevel tab should appear each time you run this way.
  6. On Macs, you may need to create a "Run Configuration..." before you can run the executable (Run » Run Configurations..). Select "OCaml Executable" and press the 'New' button to create a configuration. Name the configuration and provide the "Project name:" and "Executable file to run:" information. Leave the "Command line arguments" field blank.