ocaml / flexdll

a dlopen-like API for Windows
Other
97 stars 30 forks source link

Option -custom-crt should not add MSVC linker option /nodefaultlib:LIBCMT #51

Open ccuchet opened 6 years ago

ccuchet commented 6 years ago

When one wants to use LIBCMT.lib in place of default CRT library MSVCRT.lib, it is not possible with FlexDLL v0.35, because option -custom-crt prevents both to use MSVCRT.lib and LIBCMT.lib. It should only disable usage of MSVCRT.lib.

See reloc.ml lines 1005-1006: if !custom_crt then "/nodefaultlib:LIBCMT /nodefaultlib:MSVCRT " ^ extra_args else "msvcrt.lib " ^ extra_args should be: if !custom_crt then "/nodefaultlib:MSVCRT " ^ extra_args else "msvcrt.lib " ^ extra_args

Thanks

dra27 commented 6 years ago

Can I ask what your use-case is here? (welcome to GitHub, by the way!)

@alainfrisch - why was -custom-crt added? Of possible relevance, in case your memory is as bad as mine at the moment: https://sympa.inria.fr/sympa/arc/caml-list/2009-07/msg00024.html.

As it happens, I think the fix should possibly go further and not specify either /nodefaultlib, since the reason msvcrt.lib would be pulled in anyway would be because the user was linking objects compiled with cl /MD, so it should really be the caller's responsibility to say -custom-crt (disable flexlink automatically linking with the runtime dll) and then -link /nodefaultlib:msvcrt (prevent the linker automatically adding it in, because I'm linking objects which expected it).

ccuchet commented 6 years ago

Hello

We would like to use LIBCMT and not MSVCRT in an OCaml application. We compile C files with option '/MT' (not '/MD') and would like to link with LIBCMT.lib (and not MSVCRT.lib).

It is fine if FlexDLL option '-custom-crt' just avoids adding 'msvcrt.lib' and does nothing more.

Thanks

alainfrisch commented 6 years ago

Yes, my memory is at least as bad as yours. I think -custom-crt was an experiment to allow linking with libcmt, but I never really managed to make it work full scale.

@ccuchet After the suggested fix (or the "going further" variant), are you indeed able to link your OCaml application with libcmt? You probably need to recompile at least the OCaml runtime system, no?

ccuchet commented 6 years ago

Yes we compile the OCaml runtime with option /MT and after the suggested fix we can link with no errors with LIBCMT.lib (we do not use dynamic loading of DLL in our application).

dra27 commented 6 years ago

@ccuchet - thanks for the info! That's pretty that that still works. Did you completely disable native code dynamic linking in your build of OCaml, or are you just not using it?

Would you be willing to create a pull request with the change (if not, Alain or I can do so)?

ccuchet commented 6 years ago

We just do not use dynamic linking.

Can you please do the pull request for me, because I am new with Github and do not want to make mistakes :-)

Thanks