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

Add MSVC libNAME.lib and dllNAME.dll to stub libraries #6919

Conversation

jonahbeckford
Copy link
Collaborator

Setup:

Problem

In the examples below I was getting the following when trying to link with ctypes_foreign.cma:

** Fatal error: Cannot find file "-lctypes_foreign_stubs"

#119 explains why MSVC does not use -lLIBRARY but instead uses libLIBRARY.lib. In there a msvc_hack_cclibs function is introduced to transform libraries when passing to ocamlc with -cclib.

I guess by mistake msvc_hack_cclibs was never applied to stub libraries.

Before PR

Actual targets:
- _build/default/src/ctypes-foreign/ctypes_foreign.cma
Running[1]: (cd _build/default && Z:\source\dkml-compiler\_opam\bin\ocamlc.opt.exe 
-w @1..3@5..28@30..39@43@46..47@49..57@61..62-40 -strict-sequence -strict-formats -short-paths 
-keep-locs -principal -g -a -o src/ctypes-foreign/ctypes_foreign.cma 
-dllib -lctypes_foreign_stubs 
-cclib -lctypes_foreign_stubs 
-cclib -LZ:/source/bogue/_cpkgs/bin/../lib 
-cclib libffi.lib 
-cclib psapi.lib 
src/ctypes-foreign/.ctypes_foreign.objs/byte/libffi_abi.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_closure_properties.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_ffi_stubs.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_weak_ref.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_ffi.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/dl.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_foreign_basis.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_foreign_threaded_stubs.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/foreign.cmo)

After PR

The first -dllib and the first -cclib have changed correctly.

Actual targets:
- _build/default/src/ctypes-foreign/ctypes_foreign.cma
Running[1]: (cd _build/default && Z:\source\dkml-compiler\_opam\bin\ocamlc.opt.exe 
-w @1..3@5..28@30..39@43@46..47@49..57@61..62-40 -strict-sequence -strict-formats -short-paths 
-keep-locs -principal -g -a -o src/ctypes-foreign/ctypes_foreign.cma 
-dllib dllctypes_foreign_stubs.dll
-cclib libctypes_foreign_stubs.lib
-cclib -LZ:/source/bogue/_cpkgs/bin/../lib 
-cclib libffi.lib 
-cclib psapi.lib 
src/ctypes-foreign/.ctypes_foreign.objs/byte/libffi_abi.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_closure_properties.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_ffi_stubs.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_weak_ref.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_ffi.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/dl.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_foreign_basis.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/ctypes_foreign_threaded_stubs.cmo 
src/ctypes-foreign/.ctypes_foreign.objs/byte/foreign.cmo)

For later ... not in this PR

The

-cclib libctypes_foreign_stubs.lib
-cclib -LZ:/source/bogue/_cpkgs/bin/../lib -cclib libffi.lib 
-cclib psapi.lib 

should really be:

-cclib -LZ:/source/dkml-compiler/_opam/ctypes-foreign
-cclib libctypes_foreign_stubs.lib
-cclib -LZ:/source/bogue/_cpkgs/bin/../lib -cclib libffi.lib 
-cclib psapi.lib 

Without the -L I get the following when I try to use the resulting ctypes_foreign.cma:

** Fatal error: Cannot find file "libctypes_foreign_stubs.lib"

@jonahbeckford jonahbeckford force-pushed the feature-adjust-msvc-stub-cclibs branch 2 times, most recently from 79dabec to 9da6bea Compare January 23, 2023 06:08
Signed-off-by: Jonah Beckford <71855677+jonahbeckford@users.noreply.github.com>
@jonahbeckford jonahbeckford marked this pull request as ready for review January 23, 2023 06:46
@jonahbeckford
Copy link
Collaborator Author

This issue may be a side-effect of a latent bug in the OCaml compiler toolchain, which could be (or should be) aware of -lLIBNAME syntax (and convert to proper MSVC syntax) when it processes .cm[x]a files.

For now I'll stick the label "postponed" until this issue gets a good review.

@jonahbeckford jonahbeckford added the postponed This issue/PR is postponed and will be reviewed later label Jan 25, 2023
@rgrinberg
Copy link
Member

Please re-open if this is relevant and the PR is in a good state to be reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
postponed This issue/PR is postponed and will be reviewed later windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants