Install flatc on Ubuntu 24.04

Install flatc on Ubuntu 24.04

FlatBuffers is a cross-platform serialization library for efficiently storing and accessing structured data. The flatc is a FlatBuffers compiler used to compile .fbs files, which define tables, structs, enums, and other schema elements. This tutorial explains how to install flatc on Ubuntu 24.04.

Prepare environment

Ensure that the unzip package is installed to extract the flatc executable from a ZIP archive.

sudo apt update
sudo apt install -y unzip

Install flatc

Download the latest ZIP archive from releases page:

wget -qO flatc.zip https://github.com/google/flatbuffers/releases/latest/download/Linux.flatc.binary.g++-13.zip

Extract the executable from the ZIP archive to /usr/local/bin:

sudo unzip -q flatc.zip flatc -d /usr/local/bin

We can check flatc version as follows:

flatc --version

Delete the unnecessary ZIP archive:

rm -rf flatc.zip

Testing flatc

Create a .fbs file:

nano example.fbs

Add the following code, which defines a simple data structure:

namespace example;

table Person {
  name:string;
}

root_type Person;

Once the .fbs file is created, it must be compiled with the flatc compiler. The compiler parses the .fbs file and generates source files for the specified programming language. For example, the following command creates an example directory in the current working directory containing the Person.py file:

flatc --python example.fbs

The generated file for a specific language serves as a template that can be used to construct and access data according to the defined schema for serialization.

Uninstall flatc

To completely remove flatc, delete the executable file:

sudo rm -rf /usr/local/bin/flatc

For environment preparation, the unzip package was installed. It can be removed if no longer needed:

sudo apt purge --autoremove -y unzip

Leave a Comment

Cancel reply

Your email address will not be published.