GitHub|Download|Report a bug Mucc Home|Documentation»Getting Started

Getting Started with Mucc

This page gets you from nothing to a working mucc: downloading it, compiling a first program, making it your default compiler, and building mucc itself from source.

Requirements

Note To build mucc from source you also need git and make, and a C compiler: mucc itself is enough. See Building Mucc from Source.

Installing Mucc

Download the binary for your CPU into ~/.local/bin:

mkdir -p ~/.local/bin
curl -Lo ~/.local/bin/mucc https://github.com/Dom-Yan/Mucc/releases/latest/download/mucc-$(uname -m | sed s/arm64/aarch64/)-linux
chmod +x ~/.local/bin/mucc
mucc --version

That downloads mucc-x86_64-linux or mucc-aarch64-linux to match your CPU. Each release also has a .sha256 file to check the download with. It names the file as released, so check it next to a copy of that name:

cd /tmp
curl -LO https://github.com/Dom-Yan/Mucc/releases/latest/download/mucc-$(uname -m)-linux
curl -LO https://github.com/Dom-Yan/Mucc/releases/latest/download/mucc-$(uname -m)-linux.sha256
sha256sum -c mucc-$(uname -m)-linux.sha256      # mucc-x86_64-linux: OK

Your First Program

// hello.c
#include <stdio.h>

int main(void) {
  printf("hello, world\n");
  return 0;
}
mucc -o hello hello.c
./hello

hello is a static executable: copy it to any Linux machine with the same kind of CPU and it runs there, whatever C library that machine has.

A Program in Several Files

mucc -c main.c                   # main.o
mucc -c util.c                   # util.o
mucc -o prog main.o util.o       # link them
mucc -o prog main.c util.c       # or all at once

A Static Library

mucc -c a.c b.c
mucc -ar rcs libfoo.a a.o b.o
mucc -o prog main.c -L. -lfoo

A Program for the Other CPU

mucc --target=aarch64-linux -o hello-arm hello.c    # on an x86-64 machine
file hello-arm                                      # ELF 64-bit LSB executable, ARM aarch64

Copy hello-arm to a Raspberry Pi or an ARM server and run it there.

Note The downloaded binary carries musl for its own CPU only, so this needs a C library for the other one: a mucc built from source after make libc-aarch64 (or make libc-x86_64), or --libc=system with Debian and Ubuntu's cross glibc. The User Guide has the details.

Making Mucc Your Default Compiler

Pick the scope you want. Each one is undone by reversing its step.

One Build

Most build systems take the compiler as CC:

make CC=mucc
./configure CC=mucc AR="mucc -ar" RANLIB="mucc -ranlib"

Your Shell

Add this to ~/.bashrc (or your shell's equivalent), and every build that reads $CC uses mucc:

export CC=mucc AR="mucc -ar" RANLIB="mucc -ranlib"

Your User, as cc

Builds that run cc directly use whatever cc is first in your PATH. Put mucc there under that name (no sudo needed):

ln -s ~/.local/bin/mucc ~/.local/bin/cc
hash -r
cc --version

Undo with rm ~/.local/bin/cc.

The Whole System

On Debian, Ubuntu and their derivatives, install mucc where every user can run it and register it as an alternative for cc:

sudo install -m 755 ~/.local/bin/mucc /usr/local/bin/mucc
sudo update-alternatives --install /usr/bin/cc cc /usr/local/bin/mucc 100
cc --version

Switch back with sudo update-alternatives --config cc, or remove it with sudo update-alternatives --remove cc /usr/local/bin/mucc.

Keep gcc or clang around Anything that needs what mucc doesn't do (C++, sanitizers, LTO) still needs gcc or clang, so keep them installed alongside it.

Building Mucc from Source

You need git and make, plus a C compiler: either mucc itself or gcc.

With Only Mucc (No gcc)

Install mucc as in Installing Mucc, then:

git clone https://github.com/Dom-Yan/Mucc.git && cd Mucc
make CC=mucc        # ./mucc, the compiler
make libc           # musl, built by mucc
make build/mucc     # the single binary, as released
build/mucc --version

This takes well under a minute. It is how releases are built: each one by the release before it, with gcc and binutils made to fail so nothing else takes part (test/bootstrap.sh).

With gcc

sudo apt install build-essential git        # Ubuntu, Debian, WSL
sudo dnf install gcc make git glibc-devel   # Fedora
sudo pacman -S base-devel git               # Arch

git clone https://github.com/Dom-Yan/Mucc.git && cd Mucc
make && make libc && make build/mucc

What the Build Makes

FileWhat it is
./muccThe compiler, built by your C compiler. It uses the system's glibc by default, and the bundled musl with --libc=mucc after make libc.
build/musl/musl, built by mucc, with musl's and Linux's headers (make libc).
build/muccThe single binary: mucc built by mucc, with its headers and musl packed inside, as released.
build/mucc-aarch64The same for the other CPU (make build/mucc-aarch64, or -x86_64 on ARM64).

Installing What You Built

Either copy the single binary over the downloaded one:

cp build/mucc ~/.local/bin/mucc

or install ./mucc with its headers and musl:

make install                        # into /usr/local (needs sudo)
make install PREFIX=$HOME/.local    # into ~/.local, no sudo
make uninstall                      # removes it again

Notes

Directory Layout

DirectoryWhat's in it
src/The compiler, one stage per file (see How Mucc Works)
include/mucc's own headers (stddef.h, stdarg.h, intrinsics, ...), used before the C library's
runtime/arm64.c, the long double and 128-bit routines ARM64 code needs
thirdparty/musl and Linux's headers, as released by their projects
test/The test suite (see Testing)
docs/This website

Next Steps