In Odin, packages are directories. The system is designed to be straightforward, avoiding the complex dependency nesting found in other languages.
The Golden Rule: One Folder, One Package
- Every
.odinfile inside a specific folder must belong to the same package (e.g.,package bigint). - All files within that folder share the same scope. You do not need to "include" or "import" files that live in the same directory; they see each other automatically.
Project Structure & Imports
We assume a standard project structure where your root contains your entry point (like main.odin) or your ols.json configuration.
-
Local Packages: Any folder inside your project directory is a package.
-
Path-Based Importing: To use a local package, you import it using its relative path.
- If you have
/src/math/bigint/, you would use:import "math/bigint".
- If you have
-
Accessing Content: Once imported, you access the package's procedures and data using the package name as a prefix:
bigint.add(a, b).
Key Distinctions
- Collections: Names like
core:,base:, andvendor:are special "collections" provided by the compiler. These are for libraries that live outside your specific project folder. - Namespaces: Unlike some languages, the directory name is the "address," but the
packagedeclaration inside the file is the "identity" you use in your code.
Pro-tip: If you find yourself overthinking it, remember: If it's in a new folder, it's a new package. If it's in the same folder, it's the same package.