* Missing something in getting C and Ocaml to Work Together @ 2000-11-20 21:05 Steve Stevenson 2000-11-22 10:06 ` Wolfgang Lux 2000-11-22 20:29 ` Xavier Leroy 0 siblings, 2 replies; 6+ messages in thread From: Steve Stevenson @ 2000-11-20 21:05 UTC (permalink / raw) To: caml-list Good Afternoon, I have a very simple application. I have the main in ocaml and the rest of the system in C. I'm just trying something very straight forward. external cmainarg : int -> string array -> unit = "cmainarg" external io_infile_stdin : unit -> unit = "io_infile_stdin" external cmaininit : unit -> unit = "cmaininit" let main() = cmainarg (Array.length Sys.argv) Sys.argv; io_infile_stdin (); cmaininit(); 0 (*end*) And I use this to compile ocamlc main.cmo -custom -cclib csrc/libmainc.a When I do, I get no errors but ocamlrun a.out produces Fatal error: this bytecode file cannot run on this bytecode interpreter Mismatch on primitive `cmainarg' What am I doing wrong? Thanks. (NO, I don't know who will be president yet. :-) steve ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Missing something in getting C and Ocaml to Work Together 2000-11-20 21:05 Missing something in getting C and Ocaml to Work Together Steve Stevenson @ 2000-11-22 10:06 ` Wolfgang Lux 2000-11-22 20:29 ` Xavier Leroy 1 sibling, 0 replies; 6+ messages in thread From: Wolfgang Lux @ 2000-11-22 10:06 UTC (permalink / raw) To: Steve Stevenson; +Cc: caml-list Steve Stevenson wrote > And I use this to compile > > ocamlc main.cmo -custom -cclib csrc/libmainc.a > > When I do, I get no errors but > > ocamlrun a.out > > produces > > Fatal error: this bytecode file cannot run on this bytecode interpreter > Mismatch on primitive `cmainarg' > > What am I doing wrong? You use the standard bytecode interpreter, which does not know anything about your C function, to start your custom executable. Just use ./a.out to start the program. Actually, you (nearly) never have to call ocamlrun yourself, the bytecode program contains some nice magic to start up the right bytecode interpreter for you. Regards Wolfgang -- Wolfgang Lux Phone: +49-251-83-38263 Institut fuer Wirtschaftinformatik FAX: +49-251-83-38259 Universitaet Muenster Email: wlux@uni-muenster.de ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Missing something in getting C and Ocaml to Work Together 2000-11-20 21:05 Missing something in getting C and Ocaml to Work Together Steve Stevenson 2000-11-22 10:06 ` Wolfgang Lux @ 2000-11-22 20:29 ` Xavier Leroy 2000-11-23 12:56 ` Sven LUTHER 1 sibling, 1 reply; 6+ messages in thread From: Xavier Leroy @ 2000-11-22 20:29 UTC (permalink / raw) To: Steve Stevenson; +Cc: caml-list > I have a very simple application. I have the main in ocaml and > the rest of the system in C. I'm just trying something very straight > forward. > [...] > ocamlc main.cmo -custom -cclib csrc/libmainc.a > When I do, I get no errors but > ocamlrun a.out > produces > Fatal error: this bytecode file cannot run on this bytecode interpreter > Mismatch on primitive `cmainarg' Just run a.out directly, as in "./a.out". The -custom flag to ocamlc causes it to produce a "mixed" executable containing both OCaml bytecode and a specially tailored bytecode interpreter that includes your C code. Using the standard "ocamlrun" bytecode interpreter on such an executable fails, because ocamlrun doesn't contain the C functions that the bytecode part of the mixed executable calls ("cmainarg" here). Hope this helps, - Xavier Leroy ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Missing something in getting C and Ocaml to Work Together 2000-11-22 20:29 ` Xavier Leroy @ 2000-11-23 12:56 ` Sven LUTHER 2000-11-23 22:25 ` Typing the result of a function Mattias Waldau 0 siblings, 1 reply; 6+ messages in thread From: Sven LUTHER @ 2000-11-23 12:56 UTC (permalink / raw) To: Xavier Leroy; +Cc: Steve Stevenson, caml-list On Wed, Nov 22, 2000 at 09:29:17PM +0100, Xavier Leroy wrote: > > I have a very simple application. I have the main in ocaml and > > the rest of the system in C. I'm just trying something very straight > > forward. > > [...] > > ocamlc main.cmo -custom -cclib csrc/libmainc.a > > When I do, I get no errors but > > ocamlrun a.out > > produces > > Fatal error: this bytecode file cannot run on this bytecode interpreter > > Mismatch on primitive `cmainarg' > > Just run a.out directly, as in "./a.out". The -custom flag to ocamlc > causes it to produce a "mixed" executable containing both OCaml > bytecode and a specially tailored bytecode interpreter that includes > your C code. > > Using the standard "ocamlrun" bytecode interpreter on such an > executable fails, because ocamlrun doesn't contain the C functions that > the bytecode part of the mixed executable calls ("cmainarg" here). Any news on arch independent cutsom code you spoke about some time ago ? Friendly, Sven Luther ^ permalink raw reply [flat|nested] 6+ messages in thread
* Typing the result of a function 2000-11-23 12:56 ` Sven LUTHER @ 2000-11-23 22:25 ` Mattias Waldau 2000-11-25 15:54 ` Pierre Weis 0 siblings, 1 reply; 6+ messages in thread From: Mattias Waldau @ 2000-11-23 22:25 UTC (permalink / raw) To: caml-list I know how to type the arguments, and I like to do it, since I will get the compile errors directly, not first when I use the function. Thus, I typical write a function like (* return the column called name *) let find (columns:columns) (name:column_type) = List.find ( fun column -> column.data_type = name ) columns.columns which has typing val find : columns -> column_type -> column = <fun> If I use the interactive environment, I see that I get the expected result column. I needed to see this, since this is my first use of List.find, and I wanted to be sure that it returned the column. However, I would have liked to say this already in the definition of find, that the result of my function find should be a column. How is this done? /mattias P.s. I like to type, since I think it is belongs to the documentation of the code. P.P.s. How to type arguments is not very well described in the documentation. I found one example, twice. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Typing the result of a function 2000-11-23 22:25 ` Typing the result of a function Mattias Waldau @ 2000-11-25 15:54 ` Pierre Weis 0 siblings, 0 replies; 6+ messages in thread From: Pierre Weis @ 2000-11-25 15:54 UTC (permalink / raw) To: Mattias Waldau; +Cc: caml-list > I know how to type the arguments, and I like to do it, since I will get the > compile errors directly, not first when I use the function. > > Thus, I typical write a function like > > (* return the column called name *) > let find (columns:columns) (name:column_type) = > List.find ( fun column -> column.data_type = name ) columns.columns > > which has typing > > val find : columns -> column_type -> column = <fun> > > If I use the interactive environment, I see that I get the expected result > column. I needed to see this, since this is my first use of List.find, and I > wanted to be sure that it returned the column. > > However, I would have liked to say this already in the definition of find, > that the result of my function find should be a column. How is this done? > > /mattias > > P.s. I like to type, since I think it is belongs to the documentation of the > code. I would suggest to let those types in the module interfaces where you should already have written the documentation of the code then ... > P.P.s. How to type arguments is not very well described in the > documentation. I found one example, twice. Type constraints are simply introduced by a : symbol and should normally be enclosed into parens (as in your code above). However, you can use a simpler form to constraint the results of functions, just write the constraints before the = sign: let find (columns:columns) (name:column_type) : column = List.find ( fun column -> column.data_type = name ) columns.columns Hope this helps, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/ ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2000-11-25 16:04 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2000-11-20 21:05 Missing something in getting C and Ocaml to Work Together Steve Stevenson 2000-11-22 10:06 ` Wolfgang Lux 2000-11-22 20:29 ` Xavier Leroy 2000-11-23 12:56 ` Sven LUTHER 2000-11-23 22:25 ` Typing the result of a function Mattias Waldau 2000-11-25 15:54 ` Pierre Weis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox