How to fix the Unbound module Graphics in an ocaml project

Image
From ~/pr/gitl/ocaml-gol In a constant effort to learn new programming languages, I'm currently trying to use ocaml , a free and open-source general-purpose, multi-paradigm programming language maintained at the Inria . It's basically an extension of Caml with object-oriented features. I'm mostly interested by its functionnal and pattern matching features but the module part of the language can be a bit difficult to understand for someone with little to none ML (Meta Language) background.   The error When trying to use the graphics module to create a graphical window and go just a little further than the simplest helloworld program, here is the result : If the project uses dune : (executable (name ocaml_project) (libraries lwt.unix graphics) ) with this code : let () = Printf.printf "Hello, world!\n";; Lwt_io.printf "Hello, world!\n";; Graphics.open_graph " 800x600";; The first times I built this project running the du

How to generate a pkg-config file with cmake

pkg-config is a great way to get compiler flags for a given library. Since I'm currently implementing the rainbrurpg's meta as a library (see libwsmeta's annoucement and repository) I would like to generate a pkg-config file using cmake.

The input file

We'll start with a template pc.in file :
prefix=@DEST_DIR@
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include

Name: libmylib
Description: Mylib description.
Version: 1.0

Libs: -L${libdir} @PRIVATE_LIBS@
Cflags: -I${includedir}
The @ variables will be replaced with cmake variable content : it's the process of substitution.

The cmake part

From cmake, you have to define @DEST_DIR@ and @PRIVATE_LIBS@.

set(DEST_DIR "${CMAKE_INSTALL_PREFIX}")
This will set the correct installation prefix to CMAKE_INSTALL_PREFIX.

Now, imagine you have a library list in a cmake variable. This is a comma separaetd value and you need a list of compiler flags :

foreach(LIB ${COMMA_SEAPARATED_LIST})
  set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
endforeach()

Generating the file

Now, the last part, the file generation. And here's the trick. If you simply call CONFIGURE_FILE, cmake will allow substitution in both @ and ${} variables. But you need to keep ${} variables in the pkg-config output file.

CONFIGURE_FILE("mylib.pc.in" "mylib.pc" @ONLY)
The @ONLY prevents cmake substitution of ${} variables (see configure_file documentation).

Comments

Popular posts from this blog

How to make a map of variant in C++