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¶
- A 64-bit Linux machine, x86-64 (Intel or AMD) or ARM64: Ubuntu, Debian, Fedora, Arch, Alpine, Raspberry Pi OS, CentOS 7 and later, and others. On Windows, use WSL 2.
- Nothing else. The released binary has its own assembler, linker,
headers and C library.
curl(or a browser) is only needed to download it.
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
mucc: command not found? Open a new terminal, or addexport PATH="$HOME/.local/bin:$PATH"to your~/.bashrc.- To update, run the same
curlagain. - To uninstall,
rm ~/.local/bin/mucc.
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.
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.
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¶
| File | What it is |
|---|---|
./mucc | The 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/mucc | The single binary: mucc built by mucc, with its headers and musl packed inside, as released. |
build/mucc-aarch64 | The 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¶
- On WSL 2, clone into your Linux home (
~), not/mnt/c. It is much faster. cc: not foundmeans there is no C compiler: usemake CC=muccor install gcc.
Directory Layout¶
| Directory | What'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¶
- The User Guide covers everyday use.
- The Command-Line Reference lists every option.
- FAQ and Problems answers the common questions.