caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] [Question] Compile a custom toplevel on Windows
@ 2017-04-18  7:21 paul.lachat
  2017-04-18 18:11 ` Evgeny Roubinchtein
  2017-04-19  6:31 ` Adrien Nader
  0 siblings, 2 replies; 3+ messages in thread
From: paul.lachat @ 2017-04-18  7:21 UTC (permalink / raw)
  To: caml-list


[-- Attachment #1.1: Type: text/plain, Size: 3555 bytes --]

Hello, 

I've change the toplevel of Ocaml to replace the standard input and output by named pipes on Windows. 

To achieve this, I've change the toploop.ml (https://github.com/ocaml/ocaml/blob/trunk/toplevel/toploop.ml) to include the named pipes 
of Ocamlnet (http://projects.camlcity.org/projects/dl/ocamlnet-4.1.2/doc/html-main/Netsys_win32.html#1_Supportfornamedpipes). 

After that, I tried to understand how I could compile this custom toplevel. 
I want to compile the toplevel to have a .exe, so I could avoid using Cygwin to launch the application. 

I've run the makefile of the git repository of Ocaml and tried to follow the sequence of compilation for the toplevel. 
I use ocamlopt to have a native aplication and ocamlfind to link toploop.ml with the library ocamlnet 
(via the package netsys where the win32 named pipe are defined) and unix for catching exceptions. 

I use Opam : 1.3.0~dev, Ocaml : 4.03.0 and Cygwin on Windows 7. 

So I write a Makefile (see the attachement) and when I launch it, I get this : 
______________________________________________________________________ 
ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c genprintval.mli 
ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c genprintval.ml 
ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c toploop.mli 
ocamlfind ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c toploop.ml -linkpkg -package netsys -package unix 
File "C:\OCaml64\home\Zar\toplevel_custom\_none_", line 1: 
Warning 58: no cmx file was found in path for module Netsys_win32, and its interface was not compiled with -opaque 
ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c trace.mli 
ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c trace.ml 
ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c topdirs.mli 
ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c topdirs.ml 
ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c topmain.mli 
ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c topmain.ml 
ocamlopt -g -I +compiler-libs -a -o tmp_ocamltoplevel.cmxa genprintval.cmx toploop.cmx trace.cmx topdirs.cmx topmain.cmx 
ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c topstart.ml 
ocamlfind ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -linkall -o toplevel_custom.exe tmp_ocamltoplevel.cmxa topstart.cmx tmp_ocamltoplevel.a -linkpkg -package netsys -package unix 
** Cannot resolve symbols for tmp_ocamltoplevel.a(topdirs.o): 
caml_get_current_environment 
File "caml_startup", line 1: 
Error: Error during linking 
______________________________________________________________________ 

But I don't know how to resolve this error. 
I find that "caml_get_current_environment" is defined in meta.c (and used in topdirs.ml) 
(https://github.com/ocaml/ocaml/search?utf8=%E2%9C%93&q=caml_get_current_environment+&type=) 
But I think that meta.c is in the ocamlbytecomp.cmxa library, so I don't know why the linker don't find the symbols. 

Someone know how to resolve this problem ? 

Thank you in advance ! 

[-- Attachment #1.2: Type: text/html, Size: 5114 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Makefile --]
[-- Type: text/x-makefile; name=Makefile, Size: 1297 bytes --]

CC=ocamlopt

SRCFILES=genprintval.ml toploop.ml trace.ml topdirs.ml topmain.ml
CMXFILES=$(SRCFILES:.ml=.cmx)

TOPLIBNAME=tmp_ocamltoplevel
TOPLIBA=$(addsuffix .a, ${TOPLIBNAME})
TOPLIBCMXA=$(addsuffix .cmxa, ${TOPLIBNAME})

OTHERLIB=ocamlcommon ocamlbytecomp
OTHERLIBCMXA=$(addsuffix .cmxa, ${OTHERLIB})
OTHERLIBA=$(addsuffix .a, ${OTHERLIB})

GENERALFLAGS=-g -I +compiler-libs
CFLAGS=-strict-sequence -principal -absname -bin-annot -safe-string -strict-formats

TARGET=toplevel_custom.exe

all: ${TOPLIBCMXA} topstart.cmx
	ocamlfind ${CC} ${GENERALFLAGS} ${OTHERLIBCMXA} ${OTHERLIBA} -linkall -o ${TARGET} $^ ${TOPLIBA} -linkpkg -package netsys -package unix

${TOPLIBCMXA}: ${CMXFILES}
	${CC} ${GENERALFLAGS} -a -o $@ $^

topstart.cmx: topstart.ml
	${CC} ${GENERALFLAGS} ${OTHERLIBCMXA} ${OTHERLIBA} ${CFLAGS} -c $<

toploop.cmx: toploop.ml toploop.cmi
	ocamlfind ${CC} ${GENERALFLAGS} ${OTHERLIBCMXA} ${OTHERLIBA} ${CFLAGS} -c $< -linkpkg -package netsys -package unix

%.cmx: %.ml %.cmi
	${CC} ${GENERALFLAGS} ${OTHERLIBCMXA} ${OTHERLIBA} ${CFLAGS} -c $<

%.cmi: %.mli
	${CC} ${GENERALFLAGS} ${OTHERLIBCMXA} ${OTHERLIBA} ${CFLAGS} -c $<

clean:
	@rm -f *.cmi *.cmo *.cmx *.cmt *.cmti *.o *.txt

mrproper: clean
	@rm -f ${TARGET} ${TOPLIBA} ${TOPLIBCMXA}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] [Question] Compile a custom toplevel on Windows
  2017-04-18  7:21 [Caml-list] [Question] Compile a custom toplevel on Windows paul.lachat
@ 2017-04-18 18:11 ` Evgeny Roubinchtein
  2017-04-19  6:31 ` Adrien Nader
  1 sibling, 0 replies; 3+ messages in thread
From: Evgeny Roubinchtein @ 2017-04-18 18:11 UTC (permalink / raw)
  To: paul.lachat; +Cc: OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 4949 bytes --]

Have you considered following the "standard" instructions for building a
custom toplevel:
http://caml.inria.fr/pub/docs/manual-ocaml-4.03/toplevel.html#sec275?

Also, to the best of my knowledge, the standard toplevel (ocaml) is not a
native code application.  There _is_ a native toplevel called ocamlnat, but
as of 4.03 (IIRC) it was still undocumented, and "non-standard."  If your
goal is simply to produce a stand-alone "executable" which packages the
byte code an a COFF/ELF binary into a single file, then you can use the
"-custom" flag as documented in Chapters 8 and 19 of the manual I linked to
above.

Finally, if you are using the Cygwin version of OCaml you cannot avoid
Cygwin: your executable will be linked with cygwin.dll, and you will need
to have that present in order to start your executable.  If you wish to
produce an executable that doesn't require Cygwin at run-time, you need to
use one of the non-Cygwin OCaml compilers: on Windows, you have a choice
between MSVC and MingGW.  That is documented in the README.win32 that comes
with the OCaml distribution:
https://github.com/ocaml/ocaml/blob/4.03/README.win32.adoc

Does this help, or do you have further questions?

-- 
Best,
Zhenya

On Tue, Apr 18, 2017 at 3:21 AM, <paul.lachat@edu.univ-fcomte.fr> wrote:

> Hello,
>
> I've change the toplevel of Ocaml to replace the standard input and output
> by named pipes on Windows.
>
> To achieve this, I've change the toploop.ml (https://github.com/ocaml/
> ocaml/blob/trunk/toplevel/toploop.ml) to include the named pipes
> of Ocamlnet (http://projects.camlcity.org/projects/dl/ocamlnet-4.1.2/
> doc/html-main/Netsys_win32.html#1_Supportfornamedpipes).
>
> After that, I tried to understand how I could compile this custom toplevel.
> I want to compile the toplevel to have a .exe, so I could avoid using
> Cygwin to launch the application.
>
> I've run the makefile of the git repository of Ocaml and tried to follow
> the sequence of compilation for the toplevel.
> I use ocamlopt to have a native aplication and ocamlfind to link
> toploop.ml with the library ocamlnet
> (via the package netsys where the win32 named pipe are defined) and unix
> for catching exceptions.
>
> I use Opam : 1.3.0~dev, Ocaml : 4.03.0 and Cygwin on Windows 7.
>
> So I write a Makefile (see the attachement) and when I launch it, I get
> this :
> ______________________________________________________________________
> ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa
> ocamlcommon.a ocamlbytecomp.a -c genprintval.mli
> ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa
> ocamlcommon.a ocamlbytecomp.a -c genprintval.ml
> ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa
> ocamlcommon.a ocamlbytecomp.a -c toploop.mli
> ocamlfind ocamlopt -g -I +compiler-libs ocamlcommon.cmxa
> ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -c toploop.ml -linkpkg
> -package netsys -package unix
> File "C:\OCaml64\home\Zar\toplevel_custom\_none_", line 1:
> Warning 58: no cmx file was found in path for module Netsys_win32, and its
> interface was not compiled with -opaque
> ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa
> ocamlcommon.a ocamlbytecomp.a -c trace.mli
> ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa
> ocamlcommon.a ocamlbytecomp.a -c trace.ml
> ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa
> ocamlcommon.a ocamlbytecomp.a -c topdirs.mli
> ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa
> ocamlcommon.a ocamlbytecomp.a -c topdirs.ml
> ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa
> ocamlcommon.a ocamlbytecomp.a -c topmain.mli
> ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa
> ocamlcommon.a ocamlbytecomp.a -c topmain.ml
> ocamlopt -g -I +compiler-libs -a -o tmp_ocamltoplevel.cmxa genprintval.cmx
> toploop.cmx trace.cmx topdirs.cmx topmain.cmx
> ocamlopt -g -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa
> ocamlcommon.a ocamlbytecomp.a -c topstart.ml
> ocamlfind ocamlopt -g -I +compiler-libs ocamlcommon.cmxa
> ocamlbytecomp.cmxa ocamlcommon.a ocamlbytecomp.a -linkall -o
> toplevel_custom.exe tmp_ocamltoplevel.cmxa topstart.cmx tmp_ocamltoplevel.a
> -linkpkg -package netsys -package unix
> ** Cannot resolve symbols for tmp_ocamltoplevel.a(topdirs.o):
> caml_get_current_environment
> File "caml_startup", line 1:
> Error: Error during linking
> ______________________________________________________________________
>
> But I don't know how to resolve this error.
> I find that "caml_get_current_environment" is defined in meta.c (and used
> in topdirs.ml)
> (https://github.com/ocaml/ocaml/search?utf8=%E2%9C%93&q=
> caml_get_current_environment+&type=)
> But I think that meta.c is in the ocamlbytecomp.cmxa library, so I don't
> know why the linker don't find the symbols.
>
> Someone know how to resolve this problem ?
>
> Thank you in advance !
>

[-- Attachment #2: Type: text/html, Size: 7309 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] [Question] Compile a custom toplevel on Windows
  2017-04-18  7:21 [Caml-list] [Question] Compile a custom toplevel on Windows paul.lachat
  2017-04-18 18:11 ` Evgeny Roubinchtein
@ 2017-04-19  6:31 ` Adrien Nader
  1 sibling, 0 replies; 3+ messages in thread
From: Adrien Nader @ 2017-04-19  6:31 UTC (permalink / raw)
  To: paul.lachat; +Cc: caml-list

Hi,

On Tue, Apr 18, 2017, paul.lachat@edu.univ-fcomte.fr wrote:
> I want to compile the toplevel to have a .exe, so I could avoid using Cygwin to launch the application. 

"Using Cygwin" can be quite broad, does it mean that you want to avoid
the whole cygwin setup (through its setup.exe and everything) or also
avoid the cygwin1.dll dependency?

Usually, distributing an application built with Cygwin doesn't require
distributing more than the cygwin1.dll file. For the ocaml binaries, I
think that Cygwin adds no dependency other than this file.

If it were already merely cygwin1.dll that you're trying to avoid, I
invite you to think more about it and to compare the difficulties of
doing this build with the gains of avoiding it. It's a single file,
apparently only the ocaml compiler/toplevel will be linked against it,
and chances are that you already have an infrastructure able to provide
several files (e.g. all the .cm* files).

In both cases however, the filesystem interactions will reflect the
Cygwin lineage but if you are not doing such operations, the negative
impact of Cygwin should be minimal.

-- 
Adrien Nader

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-19  6:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-18  7:21 [Caml-list] [Question] Compile a custom toplevel on Windows paul.lachat
2017-04-18 18:11 ` Evgeny Roubinchtein
2017-04-19  6:31 ` Adrien Nader

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).