21 lines
910 B
Markdown
21 lines
910 B
Markdown
|
|
# library
|
||
|
|
|
||
|
|
A static library + an executable that consumes it.
|
||
|
|
|
||
|
|
```sh
|
||
|
|
cd examples/library
|
||
|
|
crafter-build
|
||
|
|
./bin/math-app-x86_64-pc-linux-gnu-native/math-app
|
||
|
|
```
|
||
|
|
|
||
|
|
Layout:
|
||
|
|
|
||
|
|
```
|
||
|
|
mylib/MyMath.cppm # the library's module interface
|
||
|
|
main.cpp # the consumer
|
||
|
|
project.cpp # declares both, with cfg.dependencies wiring them
|
||
|
|
```
|
||
|
|
|
||
|
|
Two `Configuration` objects: a `LibraryStatic` and an `Executable` whose `dependencies` points at the lib. The build runs them in parallel and links `libMyMath.a` into `math-app` automatically. `import MyMath;` in `main.cpp` resolves through the dep graph — no header paths to hand-wire.
|
||
|
|
|
||
|
|
The `static unique_ptr<Configuration>` for the lib is the canonical lifetime pattern: the parent's `dependencies` is `vector<Configuration*>` (raw), so something needs to keep the lib alive across the function return. File-local `static` does it cleanly without a global pool.
|