# Compilation error upon doing calc exercise

**URL:** <https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074>\
**Category:** Getting Started with P4\
**Created:** [January 18, 2024, 4:17pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074 "2024-01-18T16:17:36Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![wjc-2024](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@wjc-2024](https://forum.p4.org/u/wjc-2024)\
**Post date:** [January 18, 2024, 4:17pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/1 "2024-01-18T16:17:36Z")

</div>

Hello everyone, I am a P4 beginner.  
I am doing all the exercises in the link [tutorials/exercises at master · p4lang/tutorials · GitHub](https://github.com/p4lang/tutorials/tree/master/exercises) in order on the real machine ubuntu20.04LTS.

* * *

1. Introduction and Language Basics

- [Basic Forwarding]
- [Basic Tunneling]

1. P4Runtime and the Control Plane

- [P4Runtime]

1. Monitoring and Debugging

- [Explicit Congestion Notification]
- [Multi-Hop Route Inspection]

1. Advanced Behavior

- [Source Routing]
- [Calculator]
- [Load Balancing]
- [Quality of Service]

1. Stateful Packet Processing

- [Firewall]
- [Link Monitoring]

* * *

Tonight, before I start modifying the calc.p4 in the calculator exercise, I run the make command first, then a compilation error occurred as following.

 ![2024-01-18 23-56-06 的屏幕截图](https://us1.discourse-cdn.com/flex019/uploads/p4/original/1X/61f565ee6cbd8e36cb73dbc7bdc18f0aa894832d.jpeg)

But all my exercises before calc had no compilation errors and worked fine, so I guess there should be no problem with my environment. How should I solve this compilation error?

---

<div class="post-metadata">

**Author:** ![Faris](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/faris/32/134_2.png) [@Faris](https://forum.p4.org/u/Faris)\
**Post date:** [January 18, 2024, 4:38pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/2 "2024-01-18T16:38:57Z")

</div>

The errors in the picture seem to be due to the p4 code being incomplete / has errors.  
Have you tried replacing the file in the main directory with the one in the solution folder?

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [January 18, 2024, 6:02pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/3 "2024-01-18T18:02:01Z")

</div>

Many of the exercises have partial implementations that give no compilation errors, but it would not surprise me if a few of them give compilation errors with the starting files. The README for each exercise will usually mention this, and suggest what you need to change to complete the exercise. As mentioned by another person responding, the solution directory contains complete working solutions in case you get stuck, or want to compare your solution to someone else’s.

---

<div class="post-metadata">

**Author:** ![wjc-2024](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@wjc-2024](https://forum.p4.org/u/wjc-2024)\
**Post date:** [January 19, 2024, 2:53am UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/4 "2024-01-19T02:53:51Z")

</div>

In fact, I tried replacing the file with the solution last night, but the error is same.

 ![2024-01-19 10-32-34 的屏幕截图](https://us1.discourse-cdn.com/flex019/uploads/p4/original/1X/b43945bed6a3b51c3ca1c5d9b26ea51ba6f5792d.png)

I’m guessing what caused the problem. Could you tell me what does _ **Message type “p4.config.v1.Table” has no field named “has\_initial\_entries”** _ mean? It looks like this error occurs between step 1: _ **- Using P4Info file build/calc.p4.p4info.txt…** _ and step 2: _**- Connecting to P4Runtime server on 127.0.0.1:50051 (bmv2)…**_, but I’m not sure if step 1 is completed. Could you give me some advice to locate this bug? If it’s too hard for a beginner, what could I do is only skip the compilation step.

---

<div class="post-metadata">

**Author:** ![wjc-2024](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@wjc-2024](https://forum.p4.org/u/wjc-2024)\
**Post date:** [January 19, 2024, 3:15am UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/5 "2024-01-19T03:15:20Z")

</div>

I’ve tried all the other exercises’ solutions on my computer, and there is no problem.

---

<div class="post-metadata">

**Author:** ![fruffy](https://avatars.discourse-cdn.com/v4/letter/f/a8b319/32.png) [@fruffy](https://forum.p4.org/u/fruffy)\
**Post date:** [January 19, 2024, 12:43pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/6 "2024-01-19T12:43:57Z")

</div>

Which version of P4Runtime are you using? `has_initial_entries` was added recently but the compiler does not have support for it yet.  
PR that adds it: [https://github.com/p4lang/p4runtime/pull/432](https://github.com/p4lang/p4runtime/pull/432)

Corresponding PR with fixes

> <https://github.com/p4lang/p4c/pull/4129>
>
> For example, recently the field has\_initial\_entries was added to P4Info messages… in the p4c implementation of generating P4Info files. However, if someone is testing with a version of behavioral-model built from a p4lang/PI version that has not been updated yet, then without the changes in this PR, the Merge() calls will fail if they see such an unknown message field. With these changes, they will silently allow such unknown fields.

---

<div class="post-metadata">

**Author:** ![wjc-2024](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@wjc-2024](https://forum.p4.org/u/wjc-2024)\
**Post date:** [January 19, 2024, 1:19pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/7 "2024-01-19T13:19:04Z")

</div>

I’ve skipped compiling the calc.p4 which caused the compilation error.  
Thank you and all the repliers!

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [January 19, 2024, 4:14pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/8 "2024-01-19T16:14:58Z")

</div>

fruffy this sounds like it might be an issue where the compiler is generating the new has\_initial\_entries field in P4Info file, but some other software attempting to read it is giving an error when it reads the P4Info file, probably some Python code in the tutorials repo.

If that is the case, it should be easy for me to reproduce and see if there is a fix that can be made in the tutorials repo code that causes it to ignore fields it does not recognize, vs. throwing an exception, which I recall making to some other Python code elsewhere in p4lang repos around the time that this PR was merged: [https://github.com/p4lang/p4runtime/pull/432](https://github.com/p4lang/p4runtime/pull/432)

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [January 22, 2024, 7:29pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/9 "2024-01-22T19:29:47Z")

</div>

@wjc-2024 Would you mind describing how you installed the open source P4 development software on the system where you encountered these errors?

The reason I ask is that I tried running the calc exercise from Ubuntu 20.04 VM images that I publish here: [p4-guide/bin/README-install-troubleshooting.md at master · jafingerhut/p4-guide · GitHub](https://github.com/jafingerhut/p4-guide/blob/master/bin/README-install-troubleshooting.md)

but I did not see the errors that you did. I only tried it on the latest images published, that were built from the latest source code as of 2024-Jan-01, not older ones.

---

<div class="post-metadata">

**Author:** ![hncswpy](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@hncswpy](https://forum.p4.org/u/hncswpy)\
**Post date:** [February 12, 2024, 2:17am UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/10 "2024-02-12T02:17:12Z")

</div>

I encountered the exact same problem today. When running the calc solution from scratch, I filled in the s1-runtime.json tables. It seems that the `build/*.p4.p4info.txt` has a `has_initial_entries: true` field in tables. I installed the P4 environment on a Linux VM with install-p4dev-v6.sh script in the p4-guide repo.

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [February 12, 2024, 12:10pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/11 "2024-02-12T12:10:30Z")

</div>

Thanks for that clue to this issue. It seems to be that the install-p4dev-v6.sh vs. install-p4dev-v7.sh install scripts lead to different behavior here, probably because they install different versions of the protobuf library (at least that is my current best guess, before investigating in detail). I will see if I can get to the bottom of the root cause here.

In the mean time, as far as I know, the install-p4dev-v7.sh script is superior in most ways to the install-p4dev-v6.sh script, _as long as_ you realize that you need to do `source p4setup.bash` after using it, every time you start a new shell (or put it in your ~/.bashrc file or equivalent for a different command shell if you do not use bash).

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [February 12, 2024, 1:07pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/12 "2024-02-12T13:07:09Z")

</div>

I have confirmed that the difference in behavior is due to different versions of the Protobuf library being installed. I don’t know exactly what changed between those two versions of the Protobuf library, but it is behaving differently in a “\_MergeField” call being made as a result of the tutorials Python code calling a `Merge` method.

My recommendation stands that one prefer to use the install-p4dev-v7.sh script.

---

<div class="post-metadata">

**Author:** ![hncswpy](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@hncswpy](https://forum.p4.org/u/hncswpy)\
**Post date:** [February 12, 2024, 9:22pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/13 "2024-02-12T21:22:54Z")

</div>

Appreciate the info! If I want to resolve the issue, is there an easier way than reinstalling everything through the v7 shell script?

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [February 12, 2024, 10:36pm UTC](https://forum.p4.org/t/compilation-error-upon-doing-calc-exercise/1074/14 "2024-02-12T22:36:50Z")

</div>

I would expect a system to end up in an unusable state if you attempted to run the v6 install script, then later the v7 install script, on the same system, or in the opposite order. I only test them starting from freshly installed Ubuntu or Fedora Linux systems, not with lots of related software already installed on them.

I do not know any faster way than starting from a freshly installed system, and running the v7 script.
