Skip to content

Hello, wired

A wired program has no libc: no main, no printf. wired.h gives you the replacement for both, and this page shows the smallest program that uses them.

Code

main.c
#define WIRED_MAIN /* this file provides _start, memcpy and memset */
#include "wired.h"
int wired_main(int argc, char** argv) {
(void)argc;
(void)argv;
wired_log_str("hello\n"); /* stderr */
return 0;
}

Output

Terminal window
$ ./hello
hello
  • #define WIRED_MAIN before #include "wired.h" emits the _start entry point and the memcpy/memset a -nostdlib binary needs. Define it in exactly one file.
  • _start calls your wired_main(argc, argv); its return value becomes the exit status.
  • wired_log_str writes a NUL-terminated string to stderr.

Build the SDK archive once, then compile your file freestanding against it:

Terminal window
just lib
clang -target x86_64-linux-gnu -ffreestanding -fno-stack-protector \
-fno-builtin -nostdlib -static \
-Isrc -o hello main.c build/libwired.a
./hello

Every other page in this guide builds the same way.