fdopen / opam-repository-mingw

windows package repository for OPAM (mingw and msvc)
https://fdopen.github.io/opam-repository-mingw/
Creative Commons Zero v1.0 Universal
96 stars 34 forks source link

A linking problem with naming of libraries #60

Closed johnwhitington closed 5 years ago

johnwhitington commented 5 years ago

I am building some libraries of mixed C/OCaml code, and trying to update my script for this new OCaml on Windows distribution. I hacked it to work by renaming some files, so I can send it to the customer, but it doesn't work out of the box.

The Library Unix, for example, is installed at ocaml/unix.a.

But when we add -L<path> -lunix to the command line of the system linker x86_64-w64-mingw32-ld, it looks instead for libunix.a, and fails.

The same happens with flexlink:

flexlink -chain mingw64 -exe -o cpdflibtest.exe cpdflibtest.o -L. -lcpdf -L/home/JohnWhitington/.opam/ocaml-variants.4.08.0+mingw64c/lib/ocaml -lunix -lbigarray -lws2_32 -lversion
** Fatal error: Cannot find file "-lbigarray"

Is this intentional, and is there a non-hacky way around it?

fdopen commented 5 years ago

What kind of build system do you use? The file names and naming conventions doesn't differ between unix and mingw64. If it's a handwritten script/Makefile, why not just pass $(ocamlc -where)/unix.a instead of -L$(ocamlc -where) -lunix?

johnwhitington commented 5 years ago

Yes, it's a handwritten script. Thanks for the suggestion -- i'll give it a go.

This part of the script doesn't get tested on unix (we only build static binaries there).

This script did, however, work on some previous OCaml-on-Windows solution. But I can't remember which one -- maybe Protz'?

johnwhitington commented 5 years ago

I got this working now, thanks, and have shipped both 32bit and 64bit DLLs to the customer.

However, I noticed one difference between the 32 bit and 64 bit distributions. In the 64 bit case, we have to add -cclib "-link -static-libgcc" to ensure the DLL is standalone. But on 32 bit, it seems to happen by default.

Is this difference intentional?

fdopen commented 5 years ago

Yes, you have to pass "-static-libgcc" manually now since https://github.com/ocaml/ocaml/blob/4.07.0/Changes#L199 Most of the time only 32-bit builds are affected, but it presumedly depends on the specific C code and how gcc compiles it.

johnwhitington commented 5 years ago

Thanks!