Giter VIP home page Giter VIP logo

Comments (22)

toots avatar toots commented on June 3, 2024

Hi @tajmone,

You first try should be to edit the Makefile to use the host-prefixed compiling tools. For instance, change ocamlopt to: x86_64-w64-mingw32.static-ocamlopt.

You have to apply a little thinking to it because not all tools will need this change. For instance, ocamlyacc and ocamllex produce text files as, thus, are not architecture dependent.

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

Thanks a lot @toots ! this tip was precious, it sets me in motion in the right direction.

I'll let you know how it went.

from opam-cross-windows.

whitequark avatar whitequark commented on June 3, 2024

Really, the right thing to do is to replace e.g. ocamlc with ocamlfind -toolchain windows ocamlc, not add prefixes. With prefixes, you limit yourself to only one architecture.

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

I've tried this but it failed. The problem could be that the make file reuses the same macro for invoking the compiler on different source files, I might be better offer breaking up the makefile into single and plain invocations, at lease untill I make it work.

from opam-cross-windows.

whitequark avatar whitequark commented on June 3, 2024

ocamlfind ocamlc should be a drop-in replacement for ocamlc and it's a bug if it isn't.

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

Does this also apply to ocamlopt? the makefile uses ocamlopt to compile native code, not bytecode, and my intention is to cross-compile to native code also — does cross compiling distinguish between native and bytecode? or does it just produce native code?

My previous attempts to change the makefile from

MLDEP       = ocamldep -native
MLC         = ocamlopt
MLCOPTS     = -inline 23 -unsafe

to

MLDEP       = ocamldep -native
MLC         = ocamlfind -toolchain windows ocamlopt
MLCOPTS     = -inline 23 -unsafe

have failed. But I need to look better into the error reports.

@toots, you mentioned:

You have to apply a little thinking to it because not all tools will need this change. For instance, ocamlyacc and ocamllex produce text files as, thus, are not architecture dependent.

how does cross compiling to Windows handle EOL? does it use CRLF in input/ouput of text files? I thought that the EOL difference between Linux and Windows would pop its head up here, and that relying on the cross compiler also for text files would be safer within the same toolchain.

Inside Bash for Windows EOLs are handled smartly, and either CRLF or LF can be used in its context. But the project at thand is being compiled under a real linux machine (Ubuntu), not in an emulation environment.

from opam-cross-windows.

toots avatar toots commented on June 3, 2024

You shouldn't need to cross-compile for bytecode as it is by definition platform-independent. The only exception being if your project has embedded C bindings. Otherwise, all you should need is a local ocamlc(.exe) executable.

As for CRLF, do you mean that as the line return in OCaml source code? I don't think this would matter at all.

from opam-cross-windows.

whitequark avatar whitequark commented on June 3, 2024

Does this also apply to ocamlopt? the makefile uses ocamlopt to compile native code, not bytecode, and my intention is to cross-compile to native code also — does cross compiling distinguish between native and bytecode? or does it just produce native code?

Yes, it applies to every tool ocamlfind has support for.

Usage: ocamlfind query        [-help | other options] <package_name> ...
   or: ocamlfind ocamlc       [-help | other options] <file> ...
   or: ocamlfind ocamlcp      [-help | other options] <file> ...
   or: ocamlfind ocamlmklib   [-help | other options] <file> ...
   or: ocamlfind ocamlmktop   [-help | other options] <file> ...
   or: ocamlfind ocamlopt     [-help | other options] <file> ...
   or: ocamlfind ocamloptp    [-help | other options] <file> ...
   or: ocamlfind ocamldep     [-help | other options] <file> ...
   or: ocamlfind ocamlbrowser [-help | other options]
   or: ocamlfind ocamldoc     [-help | other options] <file> ...
   or: ocamlfind install      [-help | other options] <package_name> <file> ...
   or: ocamlfind remove       [-help | other options] <package_name>
   or: ocamlfind printppx     [-help | other options] <package_name> ...
   or: ocamlfind printconf    [-help] [variable]
   or: ocamlfind lint         [-help] <file>
   or: ocamlfind list
   or: ocamlfind pkg/cmd arg ...
Select toolchain with:
  ocamlfind -toolchain <t> <command>
Abbreviations:
  e.g. ocamlfind opt instead of ocamlfind ocamlopt

And you should also use ocamldep with ocamlfind. Like I said, all tools supported by ocamlfind should be used through ocamlfind.

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

After editing the make file as mentioned:

MLC         = ocamlfind -toolchain windows ocamlopt
# MLC         = ocamlopt

this is the compile error I get:

$ make
ocamlfind -toolchain windows ocamlopt unix.cmxa ver.cmx prelude.cmx err.cmx absyn.cmx env.cmx check.cmx pre.cmx gen.cmx fake.cmx parser.cmx lexer.cmx io.cmx main.cmx -o polygen
ocamlfind: [WARNING] Undefined toolchain: windows
File "_none_", line 1:
Error: main.cmx
is not a compilation unit description.
makefile:44: recipe for target 'polygen' failed
make: *** [polygen] Error 2

it looks like something is not right with cross-windows setup.

If I type ocamlfind list I get the following error in the report (reduced version):

$ ocamlfind list
findlib: [WARNING] cannot read directory /usr/lib/ocaml/METAS: No such file or directory

from opam-cross-windows.

whitequark avatar whitequark commented on June 3, 2024

You forgot to run eval $(opam config env).

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

No, OPAM init has set that in the .basharc file. I've typed it anyhow, but the error is the same.

from opam-cross-windows.

whitequark avatar whitequark commented on June 3, 2024

Well, the underlying cause here is that something is wrong with your OPAM installation.

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

I've tried the examples from the instruction page:

echo 'let () = print_endline "Hello, world!"' >helloworld.ml
ocamlfind -toolchain windows ocamlc helloworld.ml -o helloworld.byte
ocamlfind -toolchain windows ocamlopt helloworld.ml -o helloworld.native

and I also get the ocamlfind: [WARNING] Undefined toolchain: windows.

Any ideas how to check the setup, or reinstall it?

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

I'm going through all the cross-windows setup steps again, hoping it will fix it. This time I'm trying to install the 32bit version, which previously failed to compile.

from opam-cross-windows.

toots avatar toots commented on June 3, 2024

You should start with checking which ocamlfind you are using:

% which ocamlfind

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024
$ which ocamlfind
/home/myusername/.opam/4.04.0+32bit/bin/ocamlfind

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

Again, trying to install the 32bit version failed to compile.

After switching to 4.04.0+32bit and pinning as documented, when I type $ opam install ocaml-windows it fails with this error:

### stderr ###
# [...]
# win32.c: In function ‘caml_executable_name’:
# win32.c:622:7: warning: unused variable ‘retcode’ [-Wunused-variable]
#    int retcode;
#        ^~~~~~~
# fix_code.c: In function ‘caml_load_code’:
# fix_code.c:60:7: warning: implicit declaration of function ‘read’ [-Wimplicit-function-declaration]
#    if (read(fd, (char *) caml_start_code, caml_code_size) != caml_code_size)
#        ^~~~
# /bin/sh: 2: gawk: not found
# make: *** [bytecomp/opcodes.ml] Error 127

a previous attempt to install it after switching to the 64 bit version also failed. On another machine, under WSL/Ubuntu, both failed, with a different error complaining about GCC not supporting ISO C, or other C related errors.

from opam-cross-windows.

toots avatar toots commented on June 3, 2024

There seems to be an inconsistency here. The 4.04.0+32bit switch is for building for 32 bit architectures. If you intent to use the 64 bit cross-compiler you should be using the 4.04.0 switch.

As for the other issue, it looks like you just need to install the gawk binary.

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

I'm installing gawk right now, but when I compiled the 64 bit version, previously, it succeeded and didn't mention gawk. I originally intended to cross compile to 32bit, but since it always failed to compile the 32bit version I ended up using the 64bit version — which seems not to work though.

This second time I've tried to just reinstall the 64bit version it failed to compile, so I switched to the 32bit (which I'd preferr, but at any version would be fine ultimately, as a starting point).

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

Finally! The 32bit version compiled, and the tests from the homepage instruction all passed without error:

echo 'let () = print_endline "Hello, world!"' >helloworld.ml
ocamlfind -toolchain windows ocamlc helloworld.ml -o helloworld.byte
ocamlfind -toolchain windows ocamlopt helloworld.ml -o helloworld.native

Thanks, now it looks that cross-windows is properly setup, and I can focus on the makefile.

PS: I'm really sorry for bothering you so much, and grateful for you patience and kind support. I've spent over a week trying to setup OCaml under Windows, and stumbled into a lot problems (which seem to be common under Win 10), finally managing to install it under WSL/Ubuntu. So I opted to just install OCaml under linux and cross compile, but I'm entering a new arena, facing multiple new tools and challenges all at once.

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

I just wanted to confirm that I've tested the helloworld.native binary (of the above example) under Windows (renamed as .exe) and works perfectly!

from opam-cross-windows.

tajmone avatar tajmone commented on June 3, 2024

Solved!

Thank you very much, I couldn't have done it without your help. ❤️

from opam-cross-windows.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.