Command Line
Invocation
colang [options] <source.co>
One invocation handles one source file. When no action option is given, the compiler builds and links an executable.
Options
| Option | Description |
|---|---|
-h, --help | Show usage and the option list |
-v, --version | Show the compiler version (four segments), the LLVM version used, and the target platform |
-E | Preprocess only; send the expanded token listing to standard output |
-c | Compile only; produce an object file (COFF .obj for a Windows target, ELF .o for a Linux target) without linking |
-o <file> | Write the output to <file>; when omitted, the name follows the “Output files and default names” section |
-I <dir> | Add a header search directory; may also be written -I<dir> and repeated |
--target <triple> | Set the target triple (e.g. x86_64-unknown-linux-gnu); defaults to the host platform when omitted |
--resource <file> | Embed a PE resource into the executable; may be repeated. Accepts a .rc (compiled by the built-in resource compiler) or a precompiled .res (embedded as-is). Windows targets only |
-l <name>, --lib <name> | Pull external library <name> in at link time; may also be written -l<name> / --lib=<name> and repeated. The name is a bare link name (e.g. -luser32). The only way for a pure .c translation unit to name an external library |
-fno-diag-context | Do not print the source lines around diagnostics (by default the offending line ±2 lines are shown, with the column marked) |
Output files and default names
| Action | Output | Default name when -o is omitted |
|---|---|---|
| Default (compile + link) | Executable | Windows: <source basename>.exe; other platforms: <source basename> |
-c | .obj object file | <source basename>.obj |
-E | Standard output | Always goes to standard output; -o has no effect |
When -o is omitted, all of the default outputs above are written to the current working directory (the directory from which colang is invoked), not next to the source file. If the directory given to -o does not exist, the link step fails outright (cannot open output file ...); colang does not create the directory for you.
When linking, the intermediate .obj is written to the system temporary directory and removed automatically after the link.
Usage examples
All examples below are run from the command-line directory; outputs land in that same current directory:
colang hello.co # compile and link, producing hello.exe in the current directory
colang hello.co -o app.exe # same, but rename the output to app.exe
colang -c hello.co # compile only, producing hello.obj in the current directory
colang -E hello.co # preprocess only, sending the expanded token listing to standard output
colang -I myinc hello.co # add myinc as a header / import-module search directory
colang -luser32 app.c # pull in external library user32 at link time for a pure .c unit
colang --resource app.rc app.co # embed the PE resource app.rc, then link into app.exe
The four-segment version
-v prints something like:
colang 0.4.1.25
LLVM 23.1.0
target x86_64-pc-windows-msvc
model LLP64 (windows) (long=4, void*=8, wchar_t=2)
The first three segments MAJOR.MINOR.PATCH are the release version; the fourth is a build counter, increased whenever the compiler is really rebuilt (and reset to zero when the three-segment version changes). It only tells development builds apart and does not signal a functional change. The PE version info (FILEVERSION/PRODUCTVERSION) of the produced exe/dll uses the same four segments.
Default settings header
Every compilation automatically expands include/colang.h from the standard library directory ahead of the main source (silently skipped when it is not found), so you can put your own global macro definitions there. The injection applies to the main source only, not to imported modules, and works the same in plain-C and .co mode.
What -E actually prints
-E prints a line-by-line token listing, shaped like:
hello.co:3:1 keyword int
hello.co:5:12 string "hello\n"
It is meant for inspecting macro expansion, conditional pruning and file inclusion; it is not C source that can be fed back into a compiler. Also, -E stops at preprocessing and performs no syntax checking: even if the source contains syntax errors, -E still prints tokens and returns 0.
Header search
In order of decreasing priority:
- Directories given with
-Ion the command line; - The Co-provided standard header directory (
stdio.h,stdint.h,winapi.co, …), located automatically: the environment variableCOLANG_STDLIBis checked first (point it straight at the header directory); if unset, the compiler walks upward (at most 8 levels) from the directory containing thecolangexecutable and locates thatinclude/directory by the presence ofinclude/stddef.h.
The release package is a flat single-level layout — colang.exe sits next to the standard header directory include/, so it works out of the box after extraction: neither #include <stdio.h> nor import "winapi.co" needs -I. If you move the compiler elsewhere, keep colang.exe and include/ side by side, or point COLANG_STDLIB at the header directory. When the standard headers cannot be located, #include <stdio.h> fails with #include file not found.
Target platform and data model
colang drives the whole pipeline from a single target: predefined macros, type widths, code generation and linking all come from the same target triple. When --target is omitted the target defaults to the host platform (Windows/LLP64 on Windows, Linux/LP64 on Linux).
| Target | Data model | long | void* | wchar_t | Key predefined macros |
|---|---|---|---|---|---|
| Windows x64 | LLP64 | 4 | 8 | 2 | _WIN32 _WIN64 _MSC_VER __LLP64__ |
| Linux x86_64 | LP64 | 8 | 8 | 4 | __linux__ __gnu_linux__ __ELF__ __x86_64__ __LP64__ |
The data-model macros (__LLP64__/__LP64__) reflect the compiler’s real type widths and are strictly consistent with sizeof(long); standard-header typedefs such as size_t/ptrdiff_t and wchar_t are dispatched accordingly (on Linux size_t is unsigned long and wchar_t is 4 bytes, matching glibc). The width of long, together with every integer promotion and usual arithmetic conversion it takes part in, is likewise carried through the whole chain from the target (preprocessing, type inference, semantic analysis and code generation all read the same width), so on LP64 an expression involving long is evaluated as 64-bit and on LLP64 as 32-bit.
Cross-target compilation (for example
--target x86_64-unknown-linux-gnuon Windows) can produce ELF object files and IR; but the linking step uses the linker backend of the platform the compiler was built on, so linking artifacts across platforms is not currently supported.
Beyond the target-specific macros above, colang always defines one target-independent identification macro __COLANG__ (value 1), present on every platform and under any --target, so sources can test “whether this is being compiled by colang” (in the same family as __clang__ and __GNUC__).
Linker: built in
colang ships its own linker, so turning sources into an executable needs no external clang and no linker command.
- Windows: Linking requires the Windows SDK and the VC runtime libraries to be installed on the machine (they provide
libcmtand other platform libraries). colang locates them automatically, so an ordinary command prompt is enough — a Developer command prompt is not required. By default the output statically links the C runtime, so an exe you build on your machine runs on Windows machines that do not have the VC redistributable installed. - Linux: The in-process linker (
lld) statically links glibc and libgcc to produce a native ELF executable. colang automatically locatescrt1.o/crti.o/crtn.o,libc.aandlibgcc; you need the static library packages installed (Debian/Ubuntulibc6-dev). The search locations can be overridden with theCOLANG_CRT_DIR,COLANG_LINUX_SYSROOTandCOLANG_GCC_LIB_DIRenvironment variables. Statically linked executables are currently supported; dynamic PIE /.soare still under development.
Compatibility note: what you distribute is your compiled program (exe), not colang itself. No LLVM/clang tooling needs to accompany the program.
Naming an external library (-l / --lib)
Calling an OS API or any other external library requires telling the linker which library to look for. A .co source file can state it with the [[lib("X")]] attribute (see the “Attributes” chapter); a pure .c translation unit cannot write that attribute, so it uses the command-line switch instead:
colang -luser32 app.c
- Four equivalent spellings:
-l <name>,-l<name>,--lib <name>,--lib=<name>; the option may be repeated and duplicate names are deduplicated. - The name is a bare link name, the same convention as
[[lib("X")]]: writeuser32, notuser32.lib,C:\libs\user32oruser32.dll; a.libsuffix is tolerated (it is never doubled into.lib.lib). - Windows: each name becomes
-defaultlib:user32.libon the linker command line — the very same link directive that the[[lib]]attribute produces, so the two mix without conflict; library search paths are located by the linker from the local SDK / VC directories, and a missing library reportscannot open file 'xxx.lib'. - Linux: each name becomes
-l<name>inside the static link library group.
Boundaries:
--libaffects the link step only; under-cit is ignored with a notice.- A name containing path separators, quotes, whitespace or a colon is rejected outright (no guessing a path from a library name).
- It settles which library to pull in, not ownership of same-named symbols: when two libraries define the same symbol, their order decides which one is taken.
PE resource embedding
--resource embeds Windows resources (icons, version info, a manifest, …) into the produced exe and may be repeated; for example colang --resource app.rc app.co (give the .rc through --resource, not as the positional source file). Each item takes one file:
.res: a precompiled resource file, embedded as-is..rc: a resource script, compiled and embedded by colang’s built-in resource compiler — no externalrc.exeneeded.
A .rc script can #include "resource.h" for your own ID macros (system headers such as <windows.h> are not required and are skipped). The following resources are currently supported:
- icons via
ICON— automatically split and grouped, so the.icofile is given only once; - bitmaps via
BITMAP; - arbitrary binary data via
RCDATA; - an application manifest via
MANIFEST; - version info via
VERSIONINFO— fixed attributes (FILEVERSION,PRODUCTVERSION,FILEFLAGS,FILETYPE, …), plusVALUEtext underSTRINGFILEINFOandTRANSLATIONunderVARFILEINFO; - string tables via
STRINGTABLE(and itsSTRINGentries) — encoded asRT_STRINGfollowing rc.exe’s rules; multipleSTRINGTABLEblocks in the same language may be declared across the script and are merged into the same group; - accelerators via
ACCELERATORS— encoded asRT_ACCELERATORwith rc.exe’s per-entry 8-byte layout and its end-of-blockfVirt0x80 marker (reproduced for byte-for-byte parity); keys accept a quoted single character or aVK_*virtual-key name (the latter requiringVIRTKEY), the optionsVIRTKEY/NOINVERT/SHIFT/CONTROL/ALTaccumulate as bit flags, and the command must be a numeric id after macro expansion; - extended dialogs via
DIALOGEX— encoded asRT_DIALOGfollowing rc.exe’sDLGTEMPLATEEX/DLGITEMTEMPLATEEXlayout, byte-for-byte identical to rc.exe; the dialog header acceptsx,y,cx,cy[,helpID]and the optional clausesSTYLE/EXSTYLE(|-separated style expressions, which may use commonWS_*/DS_*/WS_EX_*style macros or numeric values),CAPTION,MENU,CLASS, andFONT pt,"face"[,weight[,italic[,charset]]](which automatically setsDS_SETFONT); controls includePUSHBUTTON/DEFPUSHBUTTON/CHECKBOX/RADIOBUTTON/AUTOCHECKBOX/AUTORADIOBUTTON/GROUPBOX/LTEXT/RTEXT/CTEXT/ICON/EDITTEXT/LISTBOX/COMBOBOX/SCROLLBAR(each mapping to a predefined class atom and rc.exe’s default style) plus the generalCONTROL; a control may be followed by optional style/exstyle/helpID override values; - custom types and resource names: written as a numeric ID, a quoted string, or a bare identifier (a bare identifier is upper-cased and stored without quotes as a string name/type, matching rc.exe); plus per-resource
LANGUAGEstatements.
Qualifiers such as MOVEABLE and DISKFILEONLY are accepted and ignored (they do not affect the result); LANGUAGE statements take effect.
String literals in a .rc always follow rc.exe’s rules: to embed a double quote inside a string, write "" (doubled) rather than \" (rc.exe does not treat a backslash as escaping a quote). Recognized escapes are \t, \n, \r, \a (0x08), \\, octal \0–\7 (at most 3 digits), and hex \x (at most 2 digits); any other \X keeps the backslash literally.
The VERSIONINFO (VS_VERSION_INFO) produced by the built-in resource compiler is byte-for-byte identical to rc.exe’s; the fixed attribute FILEOS uses its given value when present and defaults to 0 when omitted (matching rc.exe).
Current boundaries:
- Resource embedding applies only to the link output; with
-c(compile-only)--resourceis ignored with a note. - Only Windows targets are supported; cross-compiling to a non-Windows target reports an error.
- Script-style resources — the classic
DIALOG(non-EX form) / menusMENU— are not yet supported and produce a clear diagnostic;DIALOGEXstyles/controls use a built-in table, so custom control classes, rare style bits, and long control creation data (creation data) not listed in the table are not yet handled.
Multi-file programs
A single invocation compiles one source file. colang composes several .co source files through the import mechanism (see the “import (Module Import)” chapter).
The single .obj produced by -c is useful for inspecting the compile result. Linking several object files directly into an executable is still under development; for now, organize multi-file programs with import.
Diagnostics and exit codes
Diagnostics are printed to standard error in the form file:line:column: error: message (advisory ones as warning). There are only two exit codes: 0 on success, 1 on failure.
Each diagnostic is followed by the offending line plus two lines on either side, with a ^ below the offending line pointing at the column:
app.c:4:9: error: use of undeclared identifier 'foo'
2 | {
3 | int a = 1;
4 | a = foo + bar;
| ^
5 | return a;
6 | }
- One snippet per line: several diagnostics on the same source line share a single snippet instead of repeating it.
- Traced to the real origin: when the error is inside a header
#included by a.cosource, the snippet shows that header’s own source and line number, not the corresponding position in the main source. - Can be turned off:
-fno-diag-contextfalls back to one-line diagnostics, which keeps scripted output short. - When the position cannot be located in the file (for example at end of file), only the one-line diagnostic is printed.
Source files
Co source files use the .co extension by default (.cop for web-page based sources). A UTF-8 BOM at the start of a file is stripped automatically when it is read.
Current boundaries
-halso lists several options meant only for debugging the compiler itself (token, syntax tree and IR dumps). Their behavior and output format are not guaranteed to stay stable across versions, so this document makes no promises about them.