Modules, imports, packages
Single-file mode
A .cplus file compiled with cpc file.cplus -o bin has no imports; only intrinsics are available.
Project mode
Every import declares where the module comes from. Bare paths are rejected: the resolver makes you say "local" or "vendored".
// Local file at src/math.cplus
import "./math" as math;
math::area(2, 3);
// Vendored package — the path's first segment is the dep name from Cplus.toml
import "stdlib/io" as io;
io::println("hi");
- Local imports start with
./, resolved relative to the current file. - Vendored imports have a first segment matching a
[dependencies]entry, resolved fromvendor/<dep>/src/<rest>.cplus.
The alias is mandatory: import "X" as Y;, then you call into the module as Y::thing(...). There are no glob imports and no use. This is part of what keeps a file legible: every external name is traceable to the line that imported it.
pub for cross-file visibility
By default everything is module-private. pub exports.
pub fn answer() -> i32 { return 42; }
pub struct Public { pub field: i32 }
pub enum Color { Red, Green, Blue }
Cplus.toml
[package]
name = "myproj"
version = "0.0.1"
edition = "2026"
[[bin]]
name = "myproj"
path = "src/main.cplus"
[dependencies]
stdlib = "*"
The standard library is consumed like any other vendored package. This is the same model every package uses; see Packages for the full catalog and how dependency resolution walks the vendor/ checkout. To resolve and fetch these dependencies into vendor/ automatically, use cplus-pm.
[link] — library search paths
When a project links a native library that lives outside the linker's default search path — CUDA's lib64, a custom OpenBLAS prefix — list the directories in a [link] table:
[link]
search-paths = ["/usr/local/cuda/lib64", "/opt/openblas/lib"]
Each entry becomes both -L<dir> at link time and -Wl,-rpath,<dir> at run time, so the library resolves when you build and when you run, with no LD_LIBRARY_PATH. Relative entries resolve against the manifest directory. This is what lets the GPU & numerics packages link their vendor SDKs cleanly.