Skip to content

Multi file Projects

Derek Snider edited this page May 19, 2026 · 3 revisions

Multi-file Projects

Single-file programs are the default in madc. For larger projects, use #include to compose multiple source files.

Convention

Create a top-level file named after your application that #includes the rest in order, with int main() last:

// myapp.mad
#include "config.mad"
#include "types.mad"
#include "utils.mad"
#include "engine.mad"
// ... other source files ...
#include "main.mad"   // contains int main()

Run the whole project:

madc myapp.mad

How #include works

  • #include "file.mad" — resolves relative to the including file
  • #include <stdio.h> — checks embedded headers first, then filesystem
  • Nested includes are supported
  • Repeated includes of the same file are automatically skipped within a single compile
  • All included code shares the same global scope

Project structure example

myproject/
  myproject.mad        # top-level entry point
  config.mad           # configuration and constants
  types.mad            # struct definitions
  utils.mad            # utility functions
  main.mad             # int main()
// myproject.mad
#include "config.mad"
#include "types.mad"
#include "utils.mad"
#include "main.mad"
madc myproject.mad

Compiling to an executable

madc -o myproject myproject.mad
./myproject

The entire project compiles to a single native ELF binary.

What's next?

Clone this wiki locally