Comments (22)
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.
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.
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.
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.
ocamlfind ocamlc
should be a drop-in replacement for ocamlc
and it's a bug if it isn't.
from opam-cross-windows.
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
andocamllex
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.
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.
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.
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.
You forgot to run eval $(opam config env)
.
from opam-cross-windows.
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.
Well, the underlying cause here is that something is wrong with your OPAM installation.
from opam-cross-windows.
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.
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.
You should start with checking which ocamlfind
you are using:
% which ocamlfind
from opam-cross-windows.
$ which ocamlfind
/home/myusername/.opam/4.04.0+32bit/bin/ocamlfind
from opam-cross-windows.
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.
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.
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.
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.
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.
Solved!
Thank you very much, I couldn't have done it without your help. ❤️
from opam-cross-windows.
Related Issues (20)
- Cross-compiler has `ocamlc -config-var os_type` = `"%%OCAML_OS_TYPE%%"`
- Can not resolve symbols for libcamlrun.a(floats_b.o) HOT 4
- Sys.win32 reporting false on 32bit cross-compiler HOT 3
- Building fails due to fno-common being the default in recent versions of gcc HOT 3
- `opam install ocaml-windows` fails with compilation error for `ocaml-windows64` HOT 4
- Supporting ocaml 4.12 HOT 11
- Graphics HOT 4
- Error on building ocaml-windows HOT 5
- Error while compiling HOT 4
- ocamlfind: [WARNING] Undefined toolchain: windows
- ppx_tools_versioned-windows is broken with 4.12.0 HOT 7
- adding repository to opam HOT 1
- flexdll.h not found error when running "ocaml install ocaml-windows" HOT 13
- OCaml-windows 4.12.0 no longer builds HOT 2
- Ocaml 5 support HOT 4
- uutf-windows
- Packaging library with 3rd party dependencies HOT 1
- Cannot install `ocaml-windows` 5.1.1 HOT 6
- error compiling dune-windows (OCaml 5.1.1) HOT 3
- Zmq-windows version too old HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opam-cross-windows.