I'm trying to build the examples at https://github.com/mirage/mirage-tcpip in the folder "examples".
First I did opam install.
in the root directory to install all dependencies. Then I did dune build
and it build everything in _build
, lots of .a, .cma, .cmx, .cmi, .cmxa
files that I don't know what are for ( can somebody explain ?).
Anyways, I think the examples have to be built separately, because they have their own dune files. But I tried running dune build
on them and got:
root@66f08fd7c55b:/workspaces/ocaml_env/mirage-tcpip/examples/ping# dune build
Entering directory '/workspaces/ocaml_env/mirage-tcpip'
root@66f08fd7c55b:/workspaces/ocaml_env/mirage-tcpip/examples/ping# ls
dune ping.ml
root@66f08fd7c55b:/workspaces/ocaml_env/mirage-tcpip/examples/ping# cat dune
(executables
(names ping)
(libraries cmdliner logs logs.fmt tcpip.icmpv4-socket))
root@66f08fd7c55b:/workspaces/ocaml_env/mirage-tcpip/examples/ping# dune build ping
Entering directory '/workspaces/ocaml_env/mirage-tcpip'
Error: Don't know how to build ping
Regarding the file types in the _build
directory ( reference 1 , reference 2 ):
.a
are standard archive files (also known as static libraries) containing native code:
Arguments ending in.o or.a (.obj or.lib under Windows) are assumed to be C object files and libraries. They are passed to the C linker when linking in -custom mode (see the description of -custom below).
.cma
are the OCaml byte code equivalent of .a
files, so static libraries, but with platform-independent OCaml byte code instead of machine-dependent native code:
Arguments ending in.cma are taken to be libraries of object bytecode. A library of object bytecode packs in a single file a set of object bytecode files (.cmo files).
.cmx
contain meta-data for how to link native code object files together:
Arguments ending in.ml are taken to be source files for compilation unit implementations. ... From the file x.ml, the ocamlopt compiler produces two files: xo, containing native object code, and x.cmx, containing extra information for linking and optimization of the clients of the unit.
.cmi
are compiled interface definition files:
Arguments ending in.mli are taken to be source files for compilation unit interfaces. Interfaces specify the names exported by compilation units: they declare value names with their types, define public data types, declare abstract data types, and so on. From the file x.mli, the ocamlopt compiler produces a compiled interface in the file x.cmi.
.cmxa
are native code library files that combine .a
/ .o
and and .cmx
files, so like .a
but with additional linking information from the .cmx
files:
Arguments ending in.cmxa are taken to be libraries of object code.
Regarding the build of the ping
example, to build an executable target with dune
, you have to append .exe
to the target name ( reference ):
Note that native code executables will have the.exe extension on all platforms (including non-Windows systems).
So the full sequence of build commands would be:
Install dependencies:
$ opam install.
Build mirage-tcpip
:
$ dune build
Build the ping
example:
$ cd example/ping $ dune build ping.exe
Run the binary:
# dune exec./ping.exe 8.8.8.8
Alternatively, from the mirage-tcpip
directory:
#./_build/default/examples/ping/ping.exe 8.8.8.8
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.