# Include standard C lib in .p4

**URL:** <https://forum.p4.org/t/include-standard-c-lib-in-p4/446>\
**Category:** Getting Started with P4\
**Created:** [August 10, 2022, 11:05pm UTC](https://forum.p4.org/t/include-standard-c-lib-in-p4/446 "2022-08-10T23:05:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![svenchen](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@svenchen](https://forum.p4.org/u/svenchen)\
**Post date:** [August 10, 2022, 11:05pm UTC](https://forum.p4.org/t/include-standard-c-lib-in-p4/446/1 "2022-08-10T23:05:07Z")

</div>

Hi,

I tried to include C lib (e.g. #include \<stdlib.h\>) in .p4 file but failed compilation. I’m wondering whether p4 compiler supports it or not. Thank you very much.

---

<div class="post-metadata">

**Author:** ![ederollora](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/ederollora/32/21_2.png) [@ederollora](https://forum.p4.org/u/ederollora)\
**Post date:** [August 11, 2022, 9:02pm UTC](https://forum.p4.org/t/include-standard-c-lib-in-p4/446/2 "2022-08-11T21:02:17Z")

</div>

Hi @svenchen,

Without going into an over detailed answer, and as far as I am concerned, this is not possible. You cannot import a C standard lib and use it in a P4 file, as you would do while programming in C 🙂 . Even though you can see some similar syntax patterns in P4 programs that remind to what you can see in a `.c` file, you cannot just call `vsprintf` or `scanf` from a P4 file and expect them to work.

However, you could use them in a compiler written in C or a similar library for C++ or even in libraries that support the execution of P4 externs _in some targets_. Creating a P4 extern could be what you are looking for, and you can actually program them for the bmv2 Simple Switch or a Netronome SmartNIC, but this last one might be deprecated nowadays. There might be other targets, especially the software targets, can also support them.

PD: If anything of what I said is wrong, I would be happy if any forum member corrects me 🙂

Cheers,

---

<div class="post-metadata">

**Author:** ![svenchen](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@svenchen](https://forum.p4.org/u/svenchen)\
**Post date:** [August 12, 2022, 5:26pm UTC](https://forum.p4.org/t/include-standard-c-lib-in-p4/446/3 "2022-08-12T17:26:54Z")

</div>

Thank you so much. It’s really helpful!

Gong
