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.)
- Download the zip for the homework or lab, and extract the files.
- In OcaIDE within Eclipse, click File » New » OCaml Managed Project. Enter the homework/lab name (e.g. Lab01) for "project name" and click Finish.
- Right click on the newly created project folder and click Import... » General » File System » Next.
Click Browse (next to the From directory field), select the temporary folder containing
the extracted files from the zip
lab01_temp), and click OK.
- 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.
Delete the temporary extract folder (e.g.,
lab01_temp), 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.
- Right click on the project folder and select Properties.
- Click Ocaml Project.
- Under "Make executable for:" check off the file that you want to run (e.g., leapYear.ml). Leave "Compilation mode" as byte-code. Press Apply and OK to close the dialog.
- In your project, you should now see a new item (fileName.exe). If not, make sure your code compiles without error.
- 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.
- 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.