How To Compile Hello World With musl And tcc

Continuing my exploration of suckless tools I wanted to try compiling a program with tcc and musl. tcc stands for Tiny C Compiler, and musl is a lightweight libc alternative to glibc. I was generally sold on the principal of these tools, but I could not for the life of me find documentation on how to get these two working together.

Turns out it is rather quite trivial if you use the right OS. In my case, I was doing this on Void Linux running inside of a QEMU vm. The reason I chose Void, was because it has a musl build, so all of the tools are built with musl instead of glibc. musl-devel is not available on the glibc version.

On Void Linux, to install the necessary dependencies:

sudo xbps-install -S tcc musl-devel

What tripped me up is that on Void's packages directory page, I had not selected x86_64-musl so I couldn't find musl-devel. Once you get these two packages installed you are in business.

Write your hello world like this:

#include <stdio.h>

int main() {
  printf("Hello, World!\n");
  return 0;
}

Then with tcc we can treat this like a script and execute it:

tcc -run hello.c

That is it! Hopefully, this saves some time for other noobs like me.