# Modules, imports, packages

## Single-file mode

A `.cplus` file compiled with `cpc file.cplus -o bin` has no imports; only [intrinsics](/docs/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".

```cplus
// 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 from `vendor/<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.

```cplus
pub fn answer() -> i32 { return 42; }
pub struct Public { pub field: i32 }
pub enum Color { Red, Green, Blue }
```

## `Cplus.toml`

```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](/docs/packages) for the full catalog and how dependency resolution walks the `vendor/` checkout.
