Compilation Basics¶
CacaoLang includes a built-in compiler (cocoac v1.2.5) that can compile your .choco programs into standalone native executables.
Why Compile?¶
Compiling your CacaoLang programs offers several benefits:
- Standalone executables - Distribute without requiring the interpreter
- Performance - Native code execution
- Deployment - Single file distribution
- Protection - Source code is embedded and compiled
Basic Compilation¶
Simple Compilation¶
Compile a Choco program to an executable:
This creates an executable named myprogram (or myprogram.exe on Windows) in the current directory.
Custom Output Name¶
Specify a custom output filename:
This creates myapp (or myapp.exe).
Run the Compiled Program¶
Compilation Process¶
When you compile a Choco program, the compiler:
- Reads your
.chocosource file - Embeds the source code into a C++ wrapper
- Includes the interpreter and runtime
- Compiles everything with g++ to native code
- Links required libraries (GTK4 if using GUI)
- Outputs a standalone executable
Example¶
Create hello.choco:
print "Hello from compiled Choco!";
let name = input("What's your name? ");
print "Nice to meet you, #{name}!";
Compile it:
Run it:
Output:
GUI Applications¶
Compiling GUI applications works the same way:
// app.choco
gui_init("com.example.app");
let window = gui_window("My App", 400, 300);
let label = gui_label("Hello, GUI!");
gui_add(window, label);
gui_run();
Compile:
The compiler automatically detects GTK4 and includes necessary libraries.
Compilation Options¶
| Option | Description |
|---|---|
-o <name> |
Specify output filename (without extension) |
--no-gui |
Compile without GUI support (no GTK4 required) |
-h, --help |
Show help message |
Compilation Requirements¶
For Console Programs¶
- C++ compiler (g++)
- C++17 support
For GUI Programs¶
All of the above, plus:
- GTK4 development libraries
- pkg-config
Error Handling¶
If compilation fails, the compiler will:
- Show the error message from g++
- Provide troubleshooting suggestions
- Leave the temporary files for inspection
Common issues:
- GTK4 not found: Install GTK4 dev libraries or use
--no-gui - g++ not found: Install GCC or add to PATH
- Permission denied: Make sure you have write permissions
Distribution¶
Once compiled, you can distribute your executable along with:
- Any data files your program needs
- GTK4 runtime libraries (for GUI apps)
- README or documentation
The executable contains all the Choco code and interpreter, so users don't need CacaoLang installed.
Platform Considerations¶
Linux¶
Executables are portable across Linux distributions, but users may need GTK4 runtime libraries for GUI apps:
macOS¶
Distribute .app bundles for better integration. Users need GTK4 runtime via Homebrew.
Windows¶
Include GTK4 DLLs with your executable or use an installer to set up dependencies.
Next Steps¶
- Learn about Command-line Options
- Compile Without GUI Support
- Read about Deployment best practices