Next: Creating executables, Previous: Creating optimization files, Up: Compilation details [Contents][Index]
To compile a Mercury source file to C code, use a command such as
mmc --grade asm_fast.gc -C module_name.m
On that command line,
the --grade asm_fast.gc
part obviously specifies the grade,
while the -C
option,
whose long name is --target-code-only
,
tells the compiler to stop after generating the target language file
(in this case, module_name.c).
You can then compile module_name.c to module_name.o yourself, or you can tell the Mercury compiler to do this for you.
The command for doing it yourself is a command such as
mgnuc --grade asm_fast.gc -- -c module_name.c -o module_name.o
The part of the command line
between the command name (mgnuc
)
and to the double dash (--
)
contains the options interpreted by mgnuc
,
while the part after the double dash contains options
for the configured C compiler (usually gcc, clang, or MSVC).
The command that tells the Mercury compiler to generate both the .c and .o file of a module is
mmc --grade asm_fast.gc -c module_name.m
The -c
option, whose long name is --compile-only
,
tells the compiler to stop after compiling the Mercury code into object code.
If the source file contains nested modules, then both the main module in the file, and all the submodules nested inside it, directly or indirectly, will all get compiled first to separate .c files, and then to separate .o files.
In grades that target Java,
-C
(--target-code-only
) tells the compiler to stop
after generating module_name.java:
mmc --grade java -C module_name.m
while -c
(--compile-only
)
tells the compiler to stop
after generating module_name.class:
mmc --grade java -c module_name.m
since .class files are the Java equivalents of object files for C.
If the source file contains nested modules, then both the main module in the file, and all the submodules nested inside it, directly or indirectly, will all get compiled first to separate .java files, and then to separate .class files.
In grades that target C#,
-C
(--target-code-only
) tells the compiler to stop
after generating module_name.cs:
mmc --grade csharp -C module_name.m
Since C# does not really have any equivalent of object files,
-c
and -C
are equivalent to C# grades.
If the source file contains nested modules, then both the main module in the file, and all the submodules nested inside it, directly or indirectly, will all get compiled to separate .cs files.
Next: Creating executables, Previous: Creating optimization files, Up: Compilation details [Contents][Index]