GitHub|Download|Report a bug Mucc Home|Documentation»User Guide

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 librarymusl, built into muccthe system's glibc
Linkingstaticdynamic, as gcc does (-static for static)
Needs on the machinenothingglibc's development files (build-essential)
Programs run onany Linux for that CPUmachines with a compatible glibc
Shared libraries, dlopennoyes

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.

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:

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:

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:

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.