OCaml Graphics Setup Test

This page is intended to help you with verifying you can run applications that use the OCaml Graphics library on your computer. This is important because some of our assignments have components that will require use of this library in order to complete them.

First, create an Eclipse project for the graphics test:

  1. Download the zip file containing the files you need for the graphics test and extract them to a temporary folder (e.g. gtest_temp).
  2. In OcaIDE within Eclipse, click File » New » OCaml Managed Project. Enter GraphicsTest 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 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.
Next, configure the project:
  1. Right-click on the Eclipse project GraphicsTest in the Package Explorer window, select Properties.
  2. Select OCaml Build Flags, and add graphics.cma as a build flag for the project.
  3. Click Ocaml Project. Under "Make executable for:" check gtest.ml. 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 (gtest.exe). If not, check for the error in the "OCaml Compiler Output" tab at the bottom of the screen and contact a TA for help.
To run the executable, right click on gtest.exe in Eclipse and select Run As » OCaml Executable. If everything works, you should see the exciting image below!

Windows Graphics Issues

We have encountered issues in the past on Windows where the ocamlrun process spawned when a graphical application is launched is not stopped when the window is closed via the red X in the Windows interface. This can result in issues where Eclipse will refuse to re-compile any changes to your project. In order to fix this issue if your assignments are not compiling after being changed, you should use CTRL-ALT-DELETE to open the Task Manager, and kill all processes named ocamlrun. In general, our assignments will provide some means of exiting the program, either via a button in the program or via a button press - you should always use this method of exiting the application in order to avoid this issue.

Mac OS X Graphics Issues

In the past, students have had some issues with XQuartz/X11 and compiling OCaml Graphics on OS X. The most common error usually looks something like this:

Error: Error on dynamically loaded library:
/usr/local/lib/ocaml/stublibs/dllgraphics.so: dlopen(/usr/local/lib/ocaml/stublibs/dllgraphics.so, 138):
Library not loaded: /opt/local/lib/libX11.6.dylib
Referenced from: /usr/local/lib/ocaml/stublibs/dllgraphics.so
Reason: image not found

If that happens, see the instructions to install the X11 libraries, paying particular attention to the Mac issue with dynamic libraries.