Mucc User Guide
Mucc takes gcc's command-line flags, so most commands you'd type for gcc work unchanged. This guide covers what is particular to mucc.
Compiling and Linking¶
mucc -o prog main.c util.c # compile and link
mucc -c main.c # compile only: main.o
mucc -o prog main.o util.o # link objects
mucc -S main.c # assembly: main.s
mucc -E main.c # preprocess to stdout
mucc -fsyntax-only main.c # check, write nothing
mucc -std=c23 -o prog prog.c # C23 (c89, c99, c11, c17 and gnu* too)
Optimization flags like -O2 are accepted and ignored, so build
scripts that pass them work. Mucc always does the same register allocation
and constant folding.
The Two C Libraries¶
--libc=mucc (the default) | --libc=system | |
|---|---|---|
| C library | musl, built into mucc | the system's glibc |
| Linking | static | dynamic, as gcc does (-static for static) |
| Needs on the machine | nothing | glibc's development files (build-essential) |
| Programs run on | any Linux for that CPU | machines with a compatible glibc |
Shared libraries, dlopen | no | yes |
Use the default for portable tools. Use --libc=system for
programs that link the system's shared libraries (OpenSSL, SDL, GTK, ...),
load plugins with dlopen, or need glibc's faster
malloc and stdio:
mucc -o tool tool.c # portable, static, musl
mucc --libc=system -o app app.c -lssl -lcrypto # with system libraries
-lm, -lpthread, -ldl and -lrt
work with either: with musl they are part of the C library.
Cross-Compiling¶
mucc --target=aarch64-linux -o hello-arm hello.c # on an x86-64 machine
mucc --target=x86_64-linux -o hello-x86 hello.c # on an ARM64 machine
Any GNU triple for either CPU works, and so does clang's -target.
As with gcc on ARM64, plain char is unsigned there and
long double is 128-bit.
- The released binary carries musl for its own CPU only. To cross-compile
against musl, build from source and run
make libc-aarch64(ormake libc-x86_64). - With
--libc=system, mucc uses Debian and Ubuntu's cross glibc (sudo apt install gcc-aarch64-linux-gnu). - Programs for the other CPU run there, or here under
qemu-user.
Static Libraries¶
mucc -c a.c b.c
mucc -ar rcs libfoo.a a.o b.o # like GNU ar; mucc -ranlib too
mucc -o prog main.c -L. -lfoo
Archives are deterministic (dates, owners and modes are fixed), and objects and archives from gcc and mucc link together either way.
Assembly¶
.s files go through mucc's own assembler, and .S
files through the preprocessor first. It handles:
- AT&T syntax for x86-64, with SSE up to SSE4.2;
- ARM64's base, floating-point and common NEON instructions;
- GNU as's common directives:
.macro,.rept,.p2align,.incbin,.section, and the rest that compilers and hand-written assembly use.
Anything it doesn't know is handed to the system's as if there
is one; -fno-as-fallback makes that an error instead. Inline
asm, with operands, works as with gcc.
Debugging¶
mucc -g -o prog prog.c
gdb ./prog
-g writes DWARF that gdb understands: variables, types, lines
and source files. Without -g, as with gcc, objects carry no
paths, so they are the same bytes built in any directory. Functions have
their sizes in the symbol table, so profilers like perf can tell which
function an address is in.
Warnings and Errors¶
Errors and warnings point at the line and column, with the source line under them, like gcc's. These work as with gcc:
-Wall,-Werror,-Wname,-Wno-nameand-w;#pragma GCC diagnosticpush, pop, warning, error and ignored.
Warnings on by default include -Woverflow
(char c = 300), -Wimplicit-int and
-Wformat. A call to an undeclared function is an error, as C99
and later require.
Dependency Files¶
The -M family works as with gcc, for Makefiles that track
headers:
mucc -MMD -MP -c main.c # main.o and main.d
Headers built into the binary aren't files make could find, so they are left out of the lists.
Using Mucc in Build Systems¶
Most build systems take the compiler from CC, and the
archiver from AR:
- make:
make CC=mucc - autoconf:
./configure CC=mucc AR="mucc -ar" RANLIB="mucc -ranlib"
Mucc says it is gcc 4.2 (__GNUC__ is 4), as clang does, so
code written for gcc takes its gcc paths, and checks for newer gcc features
fall back.