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

caml_main cal #2914

Closed
vicuna opened this issue Aug 21, 2001 · 2 comments
Closed

caml_main cal #2914

vicuna opened this issue Aug 21, 2001 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Aug 21, 2001

Original bug ID: 490
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Ohad Rodeh
Version: 3.02
OS: WIN2000
Submission from: sungold1.il.ibm.com (192.116.181.41)

The caml_main(char **argv) function does not work properly, it fails to
return control to the C-code that calls it.

For example:

----------------------------- xx.c ------------------
#include "caml/mlvalues.h"
#include "caml/memory.h"
#include "caml/callback.h"
#include "caml/alloc.h"
#include <stdio.h>

int main (char **argv, int argc){
// caml_startup(argv);
caml_main(argv);

printf ("Hi, after caml-main"); fflush(stdout);
}

----------------------------- yy.ml ------------------

let _ =
print_tring "Starting-1\n"; flush stdout;
()


When file xx.obj is linked with yy.cmo, the only the line:
"Starting-1\n" is printed, the next line is not. However, if
I use caml_startup instead (with the appropriate compilation sequence,
things work fine.

The compilation script is as follows:

CFLAGS = /Ox /MT /W3 /I$(CAMLLIB)

.SUFFIXES: .cmo .ml .c .obj
.ml.cmo:
ocamlc -c $<
.c.obj:
cl /nologo $(CFLAGS) -c $&lt;

all : caml-startup

caml-main: xx.obj yy.cmo
ocamlc -o xx.exe xx.obj yy.cmo

caml-startup: xx.exe

yy.obj : yy.cmo
ocamlc -output-obj -o yy.obj yy.cmo

xx.exe : xx.obj yy.obj
cl /nologo -o xx.exe
xx.obj yy.obj
$(CAMLLIB)\libcamlrun.lib

clean:
-del /Q *.obj *.exe .cm core *.lib

force : clean all

@vicuna
Copy link
Author

vicuna commented Aug 21, 2001

Comment author: administrator

The caml_main(char **argv) function does not work properly, it fails to
return control to the C-code that calls it.

For example:
[...]
int main (char **argv, int argc){
[...]

This should be int main(int argc, char ** argv).

With this correction, the code works as expected under Unix. However,
under Windows, your "main" function is never called -- this can be
checked easily by printing a message before calling caml_main(argv).

I believe this is due to difference in linking semantics. The OCaml
runtime library (libcamlrun) contains a default definition of "main"
(as a call to caml_main()). Under Unix, a user-provided definition of
"main" overrides that given in the library, because the library is
linked after the user code. It seems that Windows works differently,
picking the last definition of "main" (i.e. that in libcamlrun)
instead of the first. I'm not sure this can be fixed easily, but I'll
have a look at it.

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Nov 27, 2001

Comment author: administrator

Close examination reveals that bytecode executable wasn't linked with -custom,
hence user-provided main() function is ignored. Could deserve a warning, but is
not a bug.

@vicuna vicuna closed this as completed Nov 27, 2001
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant