1

I'm learning Ocaml and currently I'm building a graphical interface for a game. I used Graphics and camlimages but now I would like to add some buttons. So I searched for Gtk2 and I'm having problems to compile now. This is a part of my code:

open Gamebase
open Game_imp
open Graphics
open Graphic_image 
open Images 
open Png 

let _ = GMain.init () 
 
let window = GWindow.window 
    ~title:"Simple lablgtk program"
    ~width:320 
    ~height:240 ()

I used

ocambuild -use-ocamlfind main.ml

before in order to compile combined with _tags file, but in order to include the gtk module, I tried

ocamlfind ocamlc -g -package lablgtk2 -linkpkg main.ml -o main

which seemed to work in a sample exemple, however when I combine it with my projet, I get "Error: Unbound module Gamebase". I tried

ocamlfind ocamlc -I +gamebase -g -package lablgtk2 -linkpkg main.ml -o main

but doesn't seem to work. Any hints and kind words are greatly appreciated.

upe
  • 1,862
  • 1
  • 19
  • 33
Gh0stm4chine
  • 11
  • 1
  • 2

1 Answers1

0

Simply :

ocamlfind ocamlc -g -package lablgtk2 -linkpkg  gamebase.ml main.ml -o main

Just take care of the order with which you give the ml file : gamebase.ml must be given first, because main.ml has a dependency on it.

upe
  • 1,862
  • 1
  • 19
  • 33
Pierre G.
  • 4,346
  • 1
  • 12
  • 25
  • I got the error : Error: Could not find the .cmi file for interface gamebase.mli. – Gh0stm4chine Dec 20 '16 at 15:40
  • So I figured out that I should compile the mli first using : ocamlfind ocamlc -g -package lablgtk2 -linkpkg gamebase.mli main.ml -o main but then I got Error: Unbound module Graphic_image Since I'm not using Ocamlbuild I guess he doesn't check the _tags file ? Thanks – Gh0stm4chine Dec 20 '16 at 15:42
  • I believe so. regarding your first try : is "ocamlbuild -use-ocamlfind labgtk2 main.native " working ? (without populating _tags file). – Pierre G. Dec 20 '16 at 16:50
  • I got this error : Solver failed: Ocamlbuild knows of no rules that apply to a target named labgtk2. This can happen if you ask Ocamlbuild to build a target with the wrong extension (e.g. .opt instead of .native) or if the source files live in directories that have not been specified as include directories. – Gh0stm4chine Dec 20 '16 at 18:43
  • typo in my previous comment : ocamlbuild -use-ocamlfind -pkg lablgtk2 main.native – Pierre G. Dec 20 '16 at 18:46
  • Didn't work at first, I had the Unbound module Graphic_image but this time there was a hint that I need a _tags file or myocamlbuild.ml. So I brought back the _tags file and now it's working :) Thank you ! – Gh0stm4chine Dec 20 '16 at 19:08