OCAMLC(1)

πŸ’– OCAMLC(1) πŸ’–

okay bestie, welcome to the ocamlc page from the General Commands Manual ✨ this is the OCaml bytecode compiler and she has a lot going on, but we’re gonna get through it together 🫢

🌸 NAME 🌸

ocamlc β€” The OCaml bytecode compiler

πŸ¦‹ SYNOPSIS πŸ¦‹

ocamlc [options] filename...

ocamlc.opt [options] filename...

πŸ’… DESCRIPTION πŸ’…

The OCaml bytecode compiler ocamlc(1) compiles OCaml source files into bytecode object files and links those object files together to make standalone bytecode executable files. Those executable files are then run by the bytecode interpreter ocamlrun(1) πŸ’–

The ocamlc(1) command has a command-line interface similar to the one used by most C compilers. It accepts several types of arguments and processes them sequentially, after all options have been processed:

  • 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 ocamlc(1) compiler produces a compiled interface in the file x.cmi.
  • Arguments ending in .ml are taken to be source files for compilation unit implementations. Implementations provide definitions for the names exported by the unit, and also contain expressions to be evaluated for their side-effects. From the file x.ml, the ocamlc(1) compiler produces compiled object bytecode in the file x.cmo.

If the interface file x.mli exists, the implementation x.ml is checked against the corresponding compiled interface x.cmi, which must exist. If no interface x.mli is provided, the compilation of x.ml produces a compiled interface file x.cmi in addition to the compiled object code file x.cmo. The file x.cmi produced corresponds to an interface that exports everything that is defined in the implementation x.ml.

  • Arguments ending in .cmo are taken to be compiled object bytecode. These files are linked together, along with the object files obtained by compiling .ml arguments (if any), and the OCaml standard library, to produce a standalone executable program. The order in which .cmo and .ml arguments are presented on the command line is relevant: compilation units are initialized in that order at run-time, and it is a link-time error to use a component of a unit before having initialized it. Hence, a given x.cmo file must come before all .cmo files that refer to the unit x.
  • 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). Libraries are built with ocamlc -a (see the description of the -a option below). The object files contained in the library are linked as regular .cmo files (see above), in the order specified when the .cma file was built. The only difference is that if an object file contained in a library is not referenced anywhere in the program, then it is not linked in.
  • Arguments ending in .c are passed to the C compiler, which generates a .o object file. This object file is linked with the program if the -custom flag is set (see the description of -custom below).
  • Arguments ending in .o or .a 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).
  • Arguments ending in .so are assumed to be C shared libraries (DLLs). During linking, they are searched for external C functions referenced from the OCaml code, and their names are written in the generated bytecode executable. The run-time system ocamlrun(1) then loads them dynamically at program start-up time.

The output of the linking phase is a file containing compiled bytecode that can be executed by the OCaml bytecode interpreter: the command ocamlrun(1). If caml.out is the name of the file produced by the linking phase, the command ocamlrun caml.out arg1 arg2 ... argn executes the compiled code contained in caml.out, passing it as arguments the character strings arg1 to argn. (See ocamlrun(1) for more details.)

On most systems, the file produced by the linking phase can be run directly, as in: ./caml.out arg1 arg2 ... argn. The produced file has the executable bit set, and it manages to launch the bytecode interpreter by itself.

Two versions of the bytecode compiler exist: ocamlc.byte is a bytecode executable (i.e. compiled with ocamlc(1) itself), while ocamlc.opt is a native executable (i.e. compiled with ocamlopt(1)). ocamlc.opt may not be available in all installations of OCaml. ocamlc is an alias for the fastest of the two, i.e. for ocamlc.opt if it is available, otherwise for ocamlc.byte.

✨ OPTIONS ✨

The following command-line options are recognized by ocamlc(1).

  • -a β€” Build a library (.cma file) with the object files (.cmo files) given on the command line, instead of linking them into an executable file. The name of the library must be set with the -o option.

If -custom, -cclib or -ccopt options are passed on the command line, these options are stored in the resulting .cma library. Then, linking with this library automatically adds back the -custom, -cclib and -ccopt options as if they had been provided on the command line, unless the -noautolink option is given. Additionally, a substring $CAMLORIGIN inside a -ccopt options will be replaced by the full path to the .cma library, excluding the filename.

  • -absname β€” Show absolute filenames in error messages.
  • -no-absname β€” Do not try to show absolute filenames in error messages.
  • -annot β€” Deprecated since 4.11. Please use -bin-annot instead.
  • -bin-annot β€” Dump detailed information about the compilation (types, bindings, tail-calls, etc) in binary format. The information for file src.ml is put into file src.cmt. In case of a type error, dump all the information inferred by the type-checker before the error. The annotation files produced by -bin-annot contain more information and are much more compact than the files produced by -annot.
  • -c β€” Compile only. Suppress the linking phase of the compilation. Source code files are turned into compiled files, but no executable file is produced. This option is useful to compile modules separately.
  • -cc ccomp β€” Use ccomp as the C linker when linking in "custom runtime" mode (see the -custom option) and as the C compiler for compiling .c source files.
  • -cclib -llibname β€” Pass the -llibname option to the C linker when linking in "custom runtime" mode (see the -custom option). This causes the given C library to be linked with the program.
  • -ccopt option β€” Pass the given option to the C compiler and linker, when linking in "custom runtime" mode (see the -custom option). For instance, -ccopt -Ldir causes the C linker to search for C libraries in directory dir.
  • -color mode β€” Enable or disable colors in compiler messages (especially warnings and errors). The following modes are supported:
    • auto β€” use heuristics to enable colors only if the output supports them (an ANSI-compatible tty terminal);
    • always β€” enable colors unconditionally;
    • never β€” disable color output.

The environment variable OCAML_COLOR is considered if -color is not provided. Its values are auto/always/never as above.

If -color is not provided, OCAML_COLOR is not set and the environment variable NO_COLOR is set, then color output is disabled. Otherwise, the default setting is auto, and the current heuristic checks that the TERM environment variable exists and is not empty or "dumb", and that isatty(stderr) holds.

  • -error-style mode β€” Control the way error messages and warnings are printed. The following modes are supported:
    • short β€” only print the error and its location;
    • contextual β€” like short, but also display the source code snippet corresponding to the location of the error.

The default setting is contextual.

The environment variable OCAML_ERROR_STYLE is considered if -error-style is not provided. Its values are short/contextual as above.

  • -compat-32 β€” Check that the generated bytecode executable can run on 32-bit platforms and signal an error if it cannot. This is useful when compiling bytecode on a 64-bit machine.
  • -config β€” Print the version number of ocamlc(1) and a detailed summary of its configuration, then exit.
  • -config-var β€” Print the value of a specific configuration variable from the -config output, then exit. If the variable does not exist, the exit code is non-zero.
  • -custom β€” Link in "custom runtime" mode. In the default linking mode, the linker produces bytecode that is intended to be executed with the shared runtime system, ocamlrun(1). In the custom runtime mode, the linker produces an output file that contains both the runtime system and the bytecode for the program. The resulting file is larger, but it can be executed directly, even if the ocamlrun(1) command is not installed. Moreover, the "custom runtime" mode enables linking OCaml code with user-defined C functions.

Never use the strip(1) command on executables produced by ocamlc -custom, this would remove the bytecode part of the executable.

Security warning: never set the "setuid" or "setgid" bits on executables produced by ocamlc -custom, this would make them vulnerable to attacks.

  • -depend ocamldep-args β€” Compute dependencies, as ocamldep(1) would do.
  • -dllib -llibname β€” Arrange for the C shared library dlllibname.so to be loaded dynamically by the run-time system ocamlrun(1) at program start-up time.
  • -dllib-suffixed -llibname β€” As for -dllib but the name recorded is mangled by ocamlrun(1) at program start-up time. This is used for C stub libraries; this option is used in particular by ocamlmklib -suffixed.
  • -dllpath dir β€” Add the directory dir to the run-time search path for shared C libraries. At link-time, shared libraries are searched in the standard search path (the one corresponding to the -I option). The -dllpath option simply stores dir in the produced executable file, where ocamlrun(1) can find it and use it.
  • -for-pack module-path β€” makes a .cmo file that later gets folded in as a sub-module (with the access path you gave) of a compilation unit built with -pack. Like, ocamlc -for-pack P -c A.ml gives you a.cmo that you can then feed to ocamlc -pack -o P.cmo a.cmo. Heads up though: you can still pack a module compiled without -for-pack, it's just that exceptions will be printed with the wrong names 😬 so, yeah, do the thing.
  • -g β€” adds debugging information while compiling and linking. You literally need this if you wanna debug with ocamldebug(1), or get stack backtraces when the program dies on an uncaught exception. Non-negotiable tbh.
  • -no-g β€” don't record debugging info. This is the default.
  • -i β€” makes the compiler print all defined names (with their inferred types or their definitions) while compiling an implementation file (.ml). No compiled files (.cmo and .cmi) come out of this β€” it's purely a vibe-check of your types ✨ Also, since the output follows interface syntax, it's kind of a cheat code for writing an explicit interface (.mli) file: just redirect stdout to a .mli file and then edit it to delete all the declarations of unexported names. Chef's kiss.
  • -i-variance β€” prints the computed variance of type parameters for every type declaration. Without this flag, variance only shows up for private types or types without a manifest (e.g. abstract types).
  • -cmi-file filename β€” type-checks the source implementation you're compiling against the interface file you specify, bypassing the normal lookup for .mli and .cmi files.
  • -I directory β€” adds the directory to the search list for compiled interface files (.cmi), compiled object code files (.cmo), libraries (.cma), and C libraries given via -cclib -lxxx. Default order: current directory first, then the standard library directory. Anything you add with -I gets searched after the current directory, in the order it appeared on the command line, but before the standard library directory. Peep option -nostdlib too.

If your directory starts with +, it's taken relative to the standard library directory. So -I +compiler-libs adds the compiler-libs subdirectory of the standard library to the search path. Cute, right?

  • -impl filename β€” compiles filename as an implementation file, even if its extension isn't .ml. Extensions are just suggestions πŸ’…
  • -intf filename β€” compiles filename as an interface file, even if its extension isn't .mli.
  • -intf-suffix string β€” treats files ending in string as interface files (instead of the default .mli).
  • -keep-docs β€” keeps documentation strings in the generated .cmi files.
  • -keep-locs β€” keeps locations in the generated .cmi files.
  • -keywords version+list β€” sets keywords per the version+list spec.

The spec starts with an optional version number that defines the base set of keywords, followed by a +-separated list of extra keywords to add to that base set. No explicit version number? Then the base set is the keywords of the current version of OCaml. And ngl, extra keywords that don't match any known keyword in the current version of the language will trigger an error whenever they show up in the source code πŸ‘€

  • -labels β€” labels are not ignored in types, labels can be used in applications, and labelled parameters can be given in any order. This is the default. It reverts option -nolabels.
  • -launch-method method β€” says which mechanism normal bytecode executables use to find the interpreter. Supported methods:
    • exe β€” a small executable stub launcher contained in the runtime-launch-info file is prepended to the bytecode image.
    • sh β€” a #! header is used. If the full path to the required interpreter isn't suitable for a #! line, a small shell script is generated instead, using the sh interpreter found in PATH.
    • /path/interpreter β€” same as sh, except if the interpreter can't be used in a #! line then /path/interpreter is used instead of searching for sh in PATH.
  • -linkall β€” forces every module in libraries to be linked in. Without this flag, unreferenced modules stay out. When you're building a library (option -a), setting -linkall forces all subsequent links of programs involving that library to link all the modules inside it. When you're compiling a module (option -c), setting -linkall ensures that module will always be linked if it's put in a library and that library gets linked. Nobody gets left out 🫢
  • -make-runtime β€” builds a custom runtime system (in the file given by option -o) that incorporates the C object files and libraries on the command line. Later you can use that custom runtime system to run bytecode executables produced with the option ocamlc -use-runtime runtime-name.
  • -match-context-rows number β€” sets how many rows of context get used during pattern matching compilation. Lower values = faster compilation but less optimized code. Default is 32.
  • -no-alias-deps β€” doesn't record dependencies for module aliases.
  • -no-app-funct β€” deactivates the applicative behaviour of functors. With this on, every functor application generates new types in its result, so applying the same functor twice to the same argument gives you two incompatible structures. Yeah. Chaos, but intentional.
  • -noassert β€” doesn't compile assertion checks. Note that the special form assert false is always compiled, because it's typed specially. This flag does nothing when linking already-compiled files.
  • -noautolink β€” when linking .cma libraries, ignores -custom, -cclib and -ccopt options potentially contained in the libraries (if those options were given when the libraries were built). Super useful when a library carries around wrong specs for C libraries or C options β€” in that case, during linking, set -noautolink and just pass the correct C libraries and options on the command line yourself πŸ”₯
  • -nolabels β€” ignores non-optional labels in types. Labels can't be used in applications, and parameter order becomes strict. See also option -labels.
  • -nostdlib β€” doesn't automatically add the standard library directory to the list of directories searched for compiled interface files (.cmi), compiled object code files (.cmo), libraries (.cma), and C libraries specified with -cclib -lxxx. See also option -I.
  • -o filename β€” names the final output file, whatever it happens to be: an executable, a compiled object (-c), a library (-a), a packed object (-pack), or a C source or object file (-output-obj and -output-complete-obj).

The default executable output name is platform-dependent: a.out on Unix, camlprog.exe on Windows.

You can also use this when compiling but not linking an interface or implementation file (-c), in which case it sets both the name of the cmi or cmo file and the name of the compilation unit to the filename up to the first dot.

  • -opaque β€” interface files compiled with this are marked so that other compilation units depending on it won't rely on any implementation details of the compiled implementation. The native compiler won't touch the .cmx file of this unit β€” and won't even warn if it's missing. Speeds up compilation for both initial and incremental builds, at the cost of the generated code's performance. Trade-offs, bestie πŸ’…
  • -open module β€” opens the given module before processing the interface or implementation files. Give several -open options and they're processed in order, exactly as if open! module1;; … open! moduleN;; were added to the top of each file.
  • -output-obj β€” makes the linker produce a C object file instead of a bytecode executable. Perfect for wrapping OCaml code as a C library callable from any C program πŸŽ€ The output object file's name has to be set with -o. You can also use this to produce a C source file (.c extension) or a compiled shared/dynamic library (.so extension).
  • -output-complete-obj β€” same as -output-obj, except when creating an object file it also includes the runtime and autolink libraries.
  • -pack β€” builds a bytecode object file (.cmo) and its associated compiled interface (.cmi) that combines the object files on the command line, making them show up as sub-modules of the output .cmo file. Name the output .cmo with the -o option. For example:
ocamlc -pack -o p.cmo a.cmo b.cmo c.cmo

generates the compiled files p.cmo and p.cmi describing a compilation unit with three sub-modules A, B and C, matching the contents of a.cmo, b.cmo and c.cmo. You can reference those contents as P.A, P.B and P.C for the rest of the program ✨

The .cmo object files being combined must have been compiled with the appropriate -for-pack option. In the example above, a.cmo, b.cmo and c.cmo must have been compiled with ocamlc -for-pack P. No shortcuts, sorry πŸ™ˆ

  • -pp command β€” makes the compiler call the given command as a preprocessor for each source file. The output of command is redirected to an intermediate file, which then gets compiled. If there are no compilation errors, that intermediate file is deleted afterwards.
  • -ppx command β€” after parsing, pipes the abstract syntax tree through the preprocessor command. The module Ast_mapper(3) implements the external interface of a preprocessor πŸ¦‹
  • -principal β€” bestie, this one checks the information path during type-checking to make sure all types are derived in a principal way. When you're using labelled arguments and/or polymorphic methods, this flag is required to ensure future versions of the compiler will be able to infer types correctly, even if internal algorithms change. All programs accepted in -principal mode are also accepted in the default mode with equivalent types, but different binary signatures, and this may slow down type checking; yet it is a good idea to use it once before publishing source code. πŸ’…
  • -no-principal β€” do not check principality of type inference. This is the default.
  • -rectypes β€” allow arbitrary recursive types during type-checking. By default, only recursive types where the recursion goes through an object type are supported. Note that once you have created an interface using this flag, you must use it again for all dependencies. πŸŒ€
  • -no-rectypes β€” do not allow arbitrary recursive types during type-checking. This is the default.
  • -runtime-search method β€” control whether the header used by normal bytecode executables is permitted to search for the interpreter, or requires it to be at a fixed location. The following methods are supported:
    • disable β€” a fixed absolute path to the interpreter is used, and the executable will not launch if the interpreter is not found at this location.
    • fallback β€” a fixed absolute path to the interpreter is used, but if the executable cannot find the interpreter at this location then it will search first in the directory containing the executable and then in PATH.
    • enable β€” the executable searches for the interpreter first in the directory containing the executable and then in PATH. No absolute path to the interpreter is recorded.
  • -runtime-variant suffix β€” add suffix to the name of the runtime library that will be used by the program. If OCaml was configured with them, the debug (d suffix) and instrument (i suffix) runtimes can be used. πŸŽ€
  • -safe-string β€” enforce the separation between types string and bytes, thereby making strings read-only. This is the default.
  • -safer-matching β€” do not use type information to optimize pattern-matching. This allows to detect match failures even if a pattern-matching was wrongly assumed to be exhaustive. This only impacts GADT and polymorphic variant compilation. πŸ”
  • -set-runtime-default setting=value β€” when linking an executable, override the default value for a runtime setting. The only currently supported setting is:
    • standard_library_default β€” specifies the default location used by the executable to locate the Standard Library. By default, this is the absolute path to the Standard Library the compiler itself was configured with.
  • -short-paths β€” when a type is visible under several module-paths, use the shortest one when printing the type's name in inferred interfaces and error and warning messages. ✨
  • -stop-after pass β€” stop compilation after the given compilation pass. The currently supported passes are: parsing, typing.
  • -strict-sequence β€” force the left-hand part of each sequence to have type unit.
  • -no-strict-sequence β€” left-hand part of a sequence need not have type unit. This is the default.
  • -unboxed-types β€” when a type is unboxable (i.e. a record with a single argument or a concrete datatype with a single constructor of one argument) it will be unboxed unless annotated with [@@ocaml.boxed]. πŸ“¦
  • -no-unboxed-types β€” when a type is unboxable it will be boxed unless annotated with [@@ocaml.unboxed]. This is the default.
  • -unsafe β€” turn bound checking off for array and string accesses (the v.(i) and s.[i] constructs). Programs compiled with -unsafe are therefore slightly faster, but unsafe: anything can happen if the program accesses an array or string outside of its bounds. 😭
bestie, seriously: -unsafe is giving β€œyolo” and not in a cute way. Out-of-bounds access = anything can happen. You’ve been warned. πŸ’€
  • -unsafe-string β€” identify the types string and bytes, thereby making strings writable. This is intended for compatibility with old source code and should not be used with new software. 🚩
  • -use-runtime runtime-name β€” generate a bytecode executable file that can be executed on the custom runtime system runtime-name, built earlier with ocamlc -make-runtime runtime-name.
  • -v β€” print the version number of the compiler and the location of the standard library directory, then exit.
  • -verbose β€” print all external commands before they are executed, in particular invocations of the C compiler and linker in -custom mode. Useful to debug C library problems. πŸ› οΈ
  • -vnum or -version β€” print the version number of the compiler in short form (e.g. "3.11.0"), then exit.
  • -w warning-list β€” enable, disable, or mark as fatal the warnings specified by the argument warning-list.

Each warning can be enabled or disabled, and each warning can be fatal or non-fatal. If a warning is disabled, it isn't displayed and doesn't affect compilation in any way (even if it is fatal). If a warning is enabled, it is displayed normally by the compiler whenever the source code triggers it. If it is enabled and fatal, the compiler will also stop with an error after displaying it. 🚨

The warning-list argument is either a mnemonic warning specifier or a sequence of single character warning specifiers, with no separators between them. A mnemonic warning specifier is one of the following:

  • +name β€” enable warning name.
  • -name β€” disable warning name.
  • @name β€” enable and mark as fatal warning name.

A single character warning specifier is one of the following:

  • +num β€” enable warning number num.
  • -num β€” disable warning number num.
  • @num β€” enable and mark as fatal warning number num.
  • +num1..num2 β€” enable all warnings between num1 and num2 (inclusive).
  • -num1..num2 β€” disable all warnings between num1 and num2 (inclusive).
  • @num1..num2 β€” enable and mark as fatal all warnings between num1 and num2 (inclusive).
  • +letter β€” enable the set of warnings corresponding to letter. The letter may be uppercase or lowercase.
  • -letter β€” disable the set of warnings corresponding to letter. The letter may be uppercase or lowercase.
  • @letter β€” enable and mark as fatal the set of warnings corresponding to letter. The letter may be uppercase or lowercase.
  • uppercase-letter β€” enable the set of warnings corresponding to uppercase-letter.
  • lowercase-letter β€” disable the set of warnings corresponding to lowercase-letter.

The warning numbers and mnemonic names are as follows:

  • 1 [comment-start] β€” suspicious-looking start-of-comment mark.
  • 2 [comment-not-end] β€” suspicious-looking end-of-comment mark.
  • 3 β€” deprecated feature.
  • 4 [fragile-match] β€” fragile pattern matching: matching that will remain complete even if additional constructors are added to one of the variant types matched.
  • 5 [ignored-partial-application] β€” partially applied function: expression whose result has function type and is ignored.
  • 6 [labels-omitted] β€” label omitted in function application.
  • 7 [method-override] β€” method overridden without using the "method!" keyword.
  • 8 [partial-match] β€” partial match: missing cases in pattern-matching.
  • 9 [missing-record-field-pattern] β€” missing fields in a record pattern.
  • 10 [non-unit-statement] β€” expression on the left-hand side of a sequence that doesn't have type unit (and that is not a function, see warning number 5).
  • 11 [redundant-case] β€” redundant case in a pattern matching (unused match case).
  • 12 [redundant-subpat] β€” redundant sub-pattern in a pattern-matching.
  • 13 [instance-variable-override] β€” override of an instance variable.
  • 14 [illegal-backslash] β€” illegal backslash escape in a string constant.
  • 15 [implicit-public-methods] β€” private method made public implicitly.
  • 16 [unerasable-optional-argument] β€” unerasable optional argument.
  • 17 [undeclared-virtual-method] β€” undeclared virtual method.
  • 18 [not-principal] β€” non-principal type.
  • 19 [non-principal-labels] β€” type without principality.
  • 20 [ignored-extra-argument] β€” unused function argument.
  • 21 [nonreturning-statement] β€” non-returning statement.
  • 22 [preprocessor] β€” preprocessor warning.
  • 23 [useless-record-with] β€” useless record with clause.
  • 24 [bad-module-name] β€” bad module name: the source file name is not a valid OCaml module name.
  • 25 β€” deprecated: now part of warning 8.
  • 26 [unused-var] β€” suspicious unused variable: unused variable that is bound with let or as , and doesn't start with an underscore (_) character.
  • 27 [unused-var-strict] β€” innocuous unused variable: unused variable that is not bound with let nor as , and doesn't start with an underscore (_) character.
  • 28 [wildcard-arg-to-constant-constr] β€” a pattern contains a constant constructor applied to the underscore (_) pattern.
  • 29 [eol-in-string] β€” a non-escaped end-of-line was found in a string constant. This may cause portability problems between Unix and Windows. 🌍
  • 30 [duplicate-definitions] β€” two labels or constructors with the exact same name are defined in two mutually recursive types 🫠
  • 31 [module-linked-twice] β€” a module is linked twice into the same executable, bestie, pick one
  • 32 [unused-value-declaration] β€” unused value declaration
  • 33 [unused-open] β€” unused open statement
  • 34 [unused-type-declaration] β€” unused type declaration
  • 35 [unused-for-index] β€” unused for-loop index
  • 36 [unused-ancestor] β€” unused ancestor variable
  • 37 [unused-constructor] β€” unused constructor
  • 38 [unused-extension] β€” unused extension constructor
  • 39 [unused-rec-flag] β€” unused rec flag
  • 40 [name-out-of-scope] β€” constructor or label name used out of scope
  • 41 [ambiguous-name] β€” ambiguous constructor or label name
  • 42 [disambiguated-name] β€” disambiguated constructor or label name
  • 43 [nonoptional-label] β€” nonoptional label applied as optional
  • 44 [open-shadow-identifier] β€” an open statement shadows an already defined identifier
  • 45 [open-shadow-label-constructor] β€” an open statement shadows an already defined label or constructor
  • 46 [bad-env-variable] β€” error in environment variable
  • 47 [attribute-payload] β€” illegal attribute payload
  • 48 [eliminated-optional-arguments] β€” implicit elimination of optional arguments
  • 49 [no-cmi-file] β€” missing cmi file when looking up a module alias
  • 50 [unexpected-docstring] β€” unexpected documentation comment
  • 51 [wrong-tailcall-expectation] β€” function call annotated with an incorrect @tailcall attribute
  • 52 [fragile-literal-pattern] β€” fragile constant pattern
  • 53 [misplaced-attribute] β€” attribute cannot appear in this context
  • 54 [duplicated-attribute] β€” attribute used more than once on an expression
  • 55 [inlining-impossible] β€” inlining impossible, it's giving "can't sit with us"
  • 56 [unreachable-case] β€” unreachable case in a pattern-matching (based on type information)
  • 57 [ambiguous-var-in-pattern-guard] β€” ambiguous or-pattern variables under guard
  • 58 [no-cmx-file] β€” missing cmx file
  • 59 [flambda-assignment-to-non-mutable-value] β€” assignment on non-mutable value
  • 60 [unused-module] β€” unused module declaration
  • 61 [unboxable-type-in-prim-decl] β€” unannotated unboxable type in primitive declaration
  • 62 [constraint-on-gadt] β€” type constraint on GADT type declaration
  • 63 [erroneous-printed-signature] β€” erroneous printed signature
  • 64 [unsafe-array-syntax-without-parsing] β€” -unsafe used with a preprocessor returning a syntax tree
  • 65 [redefining-unit] β€” type declaration defining a new '()' constructor
  • 66 [unused-open-bang] β€” unused open! statement
  • 67 [unused-functor-parameter] β€” unused functor parameter
  • 68 [match-on-mutable-state-prevent-uncurry] β€” pattern-matching that depends on mutable state prevents the remaining arguments from being uncurried
  • 69 [unused-field] β€” unused record field
  • 70 [missing-mli] β€” missing interface file
  • 71 [unused-tmc-attribute] β€” unused @tail_mod_cons attribute
  • 72 [tmc-breaks-tailcall] β€” a tail call is turned into a non-tail call by the @tail_mod_cons transformation
  • 73 [generative-application-expects-unit] β€” a generative functor is applied to an empty structure (struct end) rather than to ()

Okay so here's the tea on the letters 🍡 β€” they stand for the following sets of warnings. Any letter that isn't mentioned here? That's the empty set, babe, it means nothing:

  • A β€” all warnings
  • C β€” 1, 2
  • D β€” 3
  • E β€” 4
  • F β€” 5
  • K β€” 32, 33, 34, 35, 36, 37, 38, 39
  • L β€” 6
  • M β€” 7
  • P β€” 8
  • R β€” 9
  • S β€” 10
  • U β€” 11, 12
  • V β€” 13
  • X β€” 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 30
  • Y β€” 26
  • Z β€” 27

The default setting is:

-w +a-4-7-9-27-29-30-32..42-44-45-48-50-60-66..70-74

And lowkey important: warnings 5 and 10 are not always triggered β€” it depends on the internals of the type checker, so don't come for me if they ghost you πŸ™ˆ

  • -warn-error warning-list β€” marks the warnings listed in warning-list as errors. The compiler straight-up stops with an error the moment one of them is emitted πŸ›‘ The warning-list means exactly the same thing as it does for -w:
    • a + sign (or an uppercase letter) marks the corresponding warnings as fatal
    • a - sign (or a lowercase letter) turns them back into non-fatal warnings
    • a @ sign both enables and marks as fatal the corresponding warnings
Note: not recommended to use -warn-error in production code, bestie 😭 because it will almost certainly prevent compiling your program with later versions of OCaml when they add new warnings or modify existing warnings.

The default setting is -warn-error -a (no warning is fatal).

  • -warn-help β€” shows the description of all available warning numbers. Very much the "let me look it up for you" icon ✨
  • -where β€” prints the location of the standard library, then exits.
  • -with-runtime β€” includes the runtime system in the generated program. This is the default, so it's already doing that for you πŸ’…
  • -without-runtime β€” the compiler does not include the runtime system (nor a reference to it) in the generated program; you have to supply it separately. Your problem now, babes.
  • - file β€” processes file as a file name, even if it starts with a dash (-) character. Yes, even then. Main character behaviour.
  • -help or --help β€” displays a short usage summary and exits. The classic.

🌈 SEE ALSO 🌈

And the OCaml user's manual, chapter "Batch compilation" πŸ“š β€” go read it, iykyk.


And that's the whole page, bestie πŸŽ€ you made it to the end!! This iconic little number is the OCAMLC(1) manual page, straight out of the OCaml docs β€” the compiler's very own. Periodt. πŸ’–βœ¨

πŸ“¦ where this page comes from