Hi all, we have a project for which we will provide support for 20+ years and a large and important part of it is written in OCaml, of course. The production server is CentOS 7 and the recent commercial issues about CentOS and RedHat are suggesting that we should switch to Docker to keep a freezed building environment.
We easily built a Docker image based on CentOS 7, thanks to the excellent job the community have done making base images available on Docker Hub.
Of course the artifacts built inside the Docker image run there, but not outside because the linker cannot find the libraries. I searched for a solution and I found this thread pointing to this blog post of @rgrinberg.
I started from ocaml/opam:alpine-3.13-ocaml-4.08 and switched opam to 4.08.1+musl+static+flambda
and a simple “hello world” using -ccopt -static
works as expected but if I add to hello.ml PostgreSQL:
dune:
(executable
(name hello)
(flags (-ccopt -static))
(libraries postgresql))
hello.ml:
let c = new Postgresql.connection ~host:"localhost" ~user:"user" ~password:"pwd" ()
let main () =
Printf.printf "Hello world...?\n%!"
let () = main ()
it doesn’t even compile, complaining with a long list of missing references:
$ dune build hello/hello.exe
ocamlopt hello/hello.exe (exit 2)
(cd _build/default && /home/opam/.opam/4.08.1+musl+static+flambda/bin/ocamlopt.opt -ccopt -static -g -o hello/hello.exe -I /home/opam/.opam/4.08.1+musl+static+flambda/lib/ocaml/threads -I /home/opam/.opam/4.08.1+musl+static+flambda/lib/postgresql /home/opam/.opam/4.08.1+musl+static+flambda/lib/ocaml/unix.cmxa /home/opam/.opam/4.08.1+musl+static+flambda/lib/ocaml/threads/threads.cmxa /home/opam/.opam/4.08.1+musl+static+flambda/lib/ocaml/bigarray.cmxa /home/opam/.opam/4.08.1+musl+static+flambda/lib/postgresql/postgresql.cmxa hello/.hello.eobjs/native/hello.cmx)
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libpq.a(fe-connect.o): in function `parseServiceFile':
fe-connect.c:(.text+0xbee): undefined reference to `pg_strncasecmp'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: fe-connect.c:(.text+0xda8): undefined reference to `pg_strcasecmp'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: fe-connect.c:(.text+0xdbf): undefined reference to `pg_strcasecmp'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: fe-connect.c:(.text+0xddb): undefined reference to `ldap_init'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: fe-connect.c:(.text+0xdff): undefined reference to `ldap_set_option'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: fe-connect.c:(.text+0xe13): undefined reference to `ldap_simple_bind'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: fe-connect.c:(.text+0xe41): undefined reference to `ldap_result'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: fe-connect.c:(.text+0xe65): undefined reference to `ldap_msgfree'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: fe-connect.c:(.text+0xe7e): undefined reference to `ldap_set_option'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: fe-connect.c:(.text+0xeb4): undefined reference to `ldap_search_st'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: fe-connect.c:(.text+0xed1): undefined reference to `ldap_msgfree'
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: fe-connect.c:(.text+0xed9): undefined reference to `ldap_err2string'
... ... ... for more than 300 lines ... ... ...
Any ideas about how to solve this problem? Is it solvable, in the first place?