# Build a project without Stdlib

**URL:** <https://discuss.ocaml.org/t/build-a-project-without-stdlib/15374>\
**Category:** Learning\
**Created:** [October 2, 2024, 8:18pm UTC](https://discuss.ocaml.org/t/build-a-project-without-stdlib/15374 "2024-10-02T20:18:50Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![dx3mod](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dx3mod/32/6740_2.png) [@dx3mod](https://discuss.ocaml.org/u/dx3mod)\
**Post date:** [October 2, 2024, 8:18pm UTC](https://discuss.ocaml.org/t/build-a-project-without-stdlib/15374/1 "2024-10-02T20:18:50Z")

</div>

I decided to experiment with compiling a project without the standard library. Why? I don’t know. But I could save ~50K. Just sharing my note about it.

You can find an example in my [repository](https://github.com/dx3mod/ocaml-without-stdlib).

I found the `-nostdlib` and `-nopervasives` (undocumented) flags and after a lot of trying I was able to do what I wanted. It doesn’t disable absolutely everything (lists and other types like `option` are available).

```auto
(flags
  :standard
  -nostdlib
  -nopervasives
  ; add runtime
  -cclib
  -lasmrun
  -ccopt
  "-L %{ocaml_where}"
  -ccopt
  "-lm -ldl")

```

```ocaml
(* stdlib.ml *)
external print_endline : string -> unit = "caml_print_endline" [@@noalloc]

(* main.ml *)
open Stdlib
let () = print_endline "hello from my stdlib"

```

Hello World program:

| | with Stdlib | without Stdlib |
| --- | --- | --- |
| **size** | 349K | 302K |

---

_[View the full topic](https://discuss.ocaml.org/t/build-a-project-without-stdlib/15374)._
