Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MSVC support for stub DLLs #119

Closed
dra27 opened this issue Jun 4, 2017 · 3 comments
Closed

Fix MSVC support for stub DLLs #119

dra27 opened this issue Jun 4, 2017 · 3 comments

Comments

@dra27
Copy link
Member

dra27 commented Jun 4, 2017

JBuilder issue: it just needs the ###### filled in

On mingw, and other Unix-like compiler toolchains, shared libraries are linked with -lfoo searching for libfoo.a. For the Microsoft toolchain, this convention doesn't apply. So for mingw I have:

   (c_library_flags (:standard -lgdi32 -luser32 -lshell32))

and for MSVC I translate this to:

   (c_library_flags (:standard gdi32.lib user32.lib shell32.lib))

However, jbuilder passes those libraries in the wrong way to various subcommands resulting in this output:

  ocamlmklib src/core/dllopam_core_stubs.dll,src/core/libopam_core_stubs.lib
user32.lib(USER32.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in gdi32.lib(GDI32.dll); second definition ignored
user32.lib(USER32.dll) : warning LNK4221: no public symbols found; archive member will be inaccessible
shell32.lib(SHELL32.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in gdi32.lib(GDI32.dll); second definition ignored
shell32.lib(SHELL32.dll) : warning LNK4221: no public symbols found; archive member will be inaccessible
advapi32.lib(ADVAPI32.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in gdi32.lib(GDI32.dll); second definition ignored
advapi32.lib(ADVAPI32.dll) : warning LNK4221: no public symbols found; archive member will be inaccessible

The warning is innocuous, but irritating. I think the correct way is to pass this option to ocamlmklib using -ldopt (I think it's OK that it's then only used to create the .dll and not also embedded in the .cma/.cmxa because I think that flexlink already deals with that further down the line). However, -ldopt can't be used in c_library_flags because it will also be passed to ocamlopt which will interpret it as requiring libdopt!

I think that ocamlmklib should handle this difference itself (see ocaml/ocaml#1189), but even if ocamlmklib is changed in 4.06, jbuilder will need to handle older versions so I think some kind of support is needed here. My preference would be for jbuilder to recognise -lfoo and automatically translate it when passing it to tools on an msvc port (possibly except if libfoo.lib actually exists, but I think this will be quite rare). See also ocaml/flexdll#32

@ghost
Copy link

ghost commented Jun 5, 2017

Would it worked if jbuilder wrapped all options in c_library_flags with -ldopt <opt> when passing them to ocamlmklib? It already wraps them with -cclib when passing them to ocamlopt.

@ghost
Copy link

ghost commented Jun 5, 2017

Technically, I'm not sure whether ocamlmklib does something special with -l... and -L... options or if it just passes them to the underlying command.

@ghost ghost closed this as completed in 6a8a440 Jun 6, 2017
@ghost
Copy link

ghost commented Jun 6, 2017

I looked a bit more into this, wrapping all options with -ldopt will not work well as ocamlmklib rearranges -L and -l options in a specific order. I added a special case for msvc, I think it should fix this issue. Once ocaml/ocaml#1189 is merged we can disable the special case for OCaml > 4.06.

@dra27 can you check that it does fixes the issue?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant