If I use the Unix module then ocamlcc fails to link (even if I used -custom to generate the bytecode), and I have to manually add to -ccopts to make it link.
Testcase:
$ cat >x.ml <<EOF
let () =
Printf.printf "Time: %f\n" (Unix.gettimeofday ())
EOF
$ ocamlfind ocamlc -package unix x.ml -linkpkg -o x.byte
$ ocamlcc -verbose x.byte
+ Running '"/home/edwin/.opam/4.00.1/bin/ocamlclean" "x.byte" -o "/tmp/tmp-ocamlcc-435ea7.byte"'... [0.10s]
+ Loading "/tmp/tmp-ocamlcc-435ea7.byte"..... [0.01s]
+ Decompiling functions.... [0.01s]
+ Folding closures... [0.01s]
+ Remapping stack access... [0.00s]
+ Computing cell types..... [0.09s]
+ Cleaning functions..... [0.00s]
+ Generating C code... [0.01s]
+ Generating "/tmp/tmp-ocamlcc-f2c38d.c"... [0.02s]
+ Removing "/tmp/tmp-ocamlcc-435ea7.byte"... done
+ Running '/home/edwin/bin/gcc -D_FILE_OFFSET_BITS=64 /tmp/tmp-ocamlcc-f2c38d.c -I /home/edwin/.opam/4.00.1/include/ocamlcc -I /home/edwin/.opam/4.00.1/include/ocamlcc/ocamlcc-byterun-4.00 -lm -ldl -lcurses -Wl,-E -O3 -Wall'.../tmp/cc5Zsv1r.o: In function `f4823':
tmp-ocamlcc-f2c38d.c:(.text+0xce2): undefined reference to `unix_gettimeofday'
/tmp/cc5Zsv1r.o: In function `ocamlcc_bytecode_main':
tmp-ocamlcc-f2c38d.c:(.text+0x32c9b): undefined reference to `unix_inet_addr_of_string'
tmp-ocamlcc-f2c38d.c:(.text+0x32ccc): undefined reference to `unix_inet_addr_of_string'
tmp-ocamlcc-f2c38d.c:(.text+0x32d91): undefined reference to `unix_inet_addr_of_string'
tmp-ocamlcc-f2c38d.c:(.text+0x32e79): undefined reference to `unix_inet_addr_of_string'
tmp-ocamlcc-f2c38d.c:(.text+0x32f87): undefined reference to `unix_gettimeofday'
collect2: error: ld returned 1 exit status
[6.09s]
Error: command '/home/edwin/bin/gcc -D_FILE_OFFSET_BITS=64 /tmp/tmp-ocamlcc-f2c38d.c -I /home/edwin/.opam/4.00.1/include/ocamlcc -I /home/edwin/.opam/4.00.1/include/ocamlcc/ocamlcc-byterun-4.00 -lm -ldl -lcurses -Wl,-E -O3 -Wall' failed.
+ Removing "/tmp/tmp-ocamlcc-f2c38d.c"... done
$ ocamlfind ocamlc x.ml -package unix -linkpkg -o x.byte -custom
$ ocamlcc -verbose x.byte
+ Running '"/home/edwin/.opam/4.00.1/bin/ocamlclean" "x.byte" -o "/tmp/tmp-ocamlcc-c868a0.byte"'... [0.11s]
+ Loading "/tmp/tmp-ocamlcc-c868a0.byte"..... [0.01s]
+ Decompiling functions.... [0.01s]
+ Folding closures... [0.01s]
+ Remapping stack access... [0.00s]
+ Computing cell types..... [0.12s]
+ Cleaning functions..... [0.00s]
+ Generating C code... [0.01s]
+ Generating "/tmp/tmp-ocamlcc-30d075.c"... [0.02s]
+ Removing "/tmp/tmp-ocamlcc-c868a0.byte"... done
+ Running '/home/edwin/bin/gcc -D_FILE_OFFSET_BITS=64 /tmp/tmp-ocamlcc-30d075.c -I /home/edwin/.opam/4.00.1/include/ocamlcc -I /home/edwin/.opam/4.00.1/include/ocamlcc/ocamlcc-byterun-4.00 -lm -ldl -lcurses -Wl,-E -O3 -Wall'.../tmp/ccFu7kNe.o: In function `f4823':
tmp-ocamlcc-30d075.c:(.text+0xce2): undefined reference to `unix_gettimeofday'
/tmp/ccFu7kNe.o: In function `ocamlcc_bytecode_main':
tmp-ocamlcc-30d075.c:(.text+0x32c9b): undefined reference to `unix_inet_addr_of_string'
tmp-ocamlcc-30d075.c:(.text+0x32ccc): undefined reference to `unix_inet_addr_of_string'
tmp-ocamlcc-30d075.c:(.text+0x32d91): undefined reference to `unix_inet_addr_of_string'
tmp-ocamlcc-30d075.c:(.text+0x32e79): undefined reference to `unix_inet_addr_of_string'
tmp-ocamlcc-30d075.c:(.text+0x32f87): undefined reference to `unix_gettimeofday'
collect2: error: ld returned 1 exit status
[6.11s]
Error: command '/home/edwin/bin/gcc -D_FILE_OFFSET_BITS=64 /tmp/tmp-ocamlcc-30d075.c -I /home/edwin/.opam/4.00.1/include/ocamlcc -I /home/edwin/.opam/4.00.1/include/ocamlcc/ocamlcc-byterun-4.00 -lm -ldl -lcurses -Wl,-E -O3 -Wall' failed.
+ Removing "/tmp/tmp-ocamlcc-30d075.c"... done
$ ocamlcc -verbose x.byte -ccopts -L`ocamlfind query unix` -ccopts -lunix
+ Running '"/home/edwin/.opam/4.00.1/bin/ocamlclean" "x.byte" -o "/tmp/tmp-ocamlcc-d9b53c.byte"'... [0.08s]
+ Loading "/tmp/tmp-ocamlcc-d9b53c.byte"..... [0.01s]
+ Decompiling functions.... [0.01s]
+ Folding closures... [0.01s]
+ Remapping stack access... [0.00s]
+ Computing cell types..... [0.09s]
+ Cleaning functions..... [0.00s]
+ Generating C code... [0.01s]
+ Generating "/tmp/tmp-ocamlcc-a7b66f.c"... [0.02s]
+ Removing "/tmp/tmp-ocamlcc-d9b53c.byte"... done
+ Running '/home/edwin/bin/gcc -D_FILE_OFFSET_BITS=64 /tmp/tmp-ocamlcc-a7b66f.c -I /home/edwin/.opam/4.00.1/include/ocamlcc -I /home/edwin/.opam/4.00.1/include/ocamlcc/ocamlcc-byterun-4.00 -lm -ldl -lcurses -Wl,-E -O3 -Wall "-L/home/edwin/.opam/4.00.1/lib/ocaml" "-lunix"'... [6.11s]
+ Removing "/tmp/tmp-ocamlcc-a7b66f.c"... done
If I use the Unix module then ocamlcc fails to link (even if I used -custom to generate the bytecode), and I have to manually add to -ccopts to make it link.
Testcase: