如何在Linux Ubuntu上安装Flatc和FlatBuffers

Ole*_*kyi 3 linux ubuntu flatbuffers

如果我们在Linux Ubuntu上安装Flatbuffers,我们将无法在任何地方使用shortc flatc命令进行编译,我们该怎么做?

例如:我想在package.json中使用一些命令“ flatc -o path / src / app / core / providers / flatbuffers .....”

为了做到这一点,不足以安装平面缓冲区,我们还需要执行许多其他操作-添加符号链接等。

Ole*_*kyi 11

针对linux ubuntu的flatc和flatbuffers解决方案

  1. 选择“安装文件夹”
  2. cd“安装文件夹”
  3. git clone https://github.com/google/flatbuffers.git
  4. cd平面缓冲区
  5. cmake -G“ Unix Makefiles”(如果需要,请安装cmake)
  6. 使
  7. 须藤ln -s / full-path-to-flatbuffer / flatbuffers / flatc / usr / local / bin / flatc
  8. chmod + x /全路径到flatbuffer / flatbuffers / flatc
  9. 在任何地方以“ flatc”运行


Gea*_*Lin 11

在 Ubuntu 20.04 (focal) 中,它已经在 apt 存储库中 ( https://packages.ubuntu.com/focal/flatbuffers-compiler ),因此你可以安装它:

sudo apt update
sudo apt install -y flatbuffers-compiler
Run Code Online (Sandbox Code Playgroud)

对于 Ubuntu 18.04(bionic),您可以使用 PPA(https://launchpad.net/~hnakamur/+archive/ubuntu/flatbuffers):

sudo apt-add-repository ppa:hnakamur/flatbuffers
sudo apt update
sudo apt install -y flatbuffers-compiler
Run Code Online (Sandbox Code Playgroud)

两者都有点旧(1.11),但如果您不使用最新功能,那么这应该相当可靠。


Cor*_*ole 10

Olexandr 的答案仅适用于 flatc 二进制文件。

要使用cmake从源代码构建和安装所有平面缓冲区,请按照此处的说明进行操作:

  • 克隆存储&cd flatbuffers
  • 为 linux ubuntu 生成构建文件
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
Run Code Online (Sandbox Code Playgroud)
  • 编译
make
Run Code Online (Sandbox Code Playgroud)
  • 安装
sudo make install
Run Code Online (Sandbox Code Playgroud)
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/include/flatbuffers
-- Installing: /usr/local/include/flatbuffers/stl_emulation.h
-- Installing: /usr/local/include/flatbuffers/flexbuffers.h
-- Installing: /usr/local/include/flatbuffers/minireflect.h
-- Installing: /usr/local/include/flatbuffers/flatbuffers.h
-- Installing: /usr/local/include/flatbuffers/pch
-- Installing: /usr/local/include/flatbuffers/pch/flatc_pch.h
-- Installing: /usr/local/include/flatbuffers/pch/pch.h
-- Installing: /usr/local/include/flatbuffers/flatc.h
-- Installing: /usr/local/include/flatbuffers/code_generators.h
-- Installing: /usr/local/include/flatbuffers/util.h
-- Installing: /usr/local/include/flatbuffers/grpc.h
-- Installing: /usr/local/include/flatbuffers/base.h
-- Installing: /usr/local/include/flatbuffers/registry.h
-- Installing: /usr/local/include/flatbuffers/hash.h
-- Installing: /usr/local/include/flatbuffers/reflection_generated.h
-- Installing: /usr/local/include/flatbuffers/idl.h
-- Installing: /usr/local/include/flatbuffers/reflection.h
-- Installing: /usr/local/lib/cmake/flatbuffers/FlatbuffersConfig.cmake
-- Installing: /usr/local/lib/cmake/flatbuffers/FlatbuffersConfigVersion.cmake
-- Installing: /usr/local/lib/libflatbuffers.a
-- Installing: /usr/local/lib/cmake/flatbuffers/FlatbuffersTargets.cmake
-- Installing: /usr/local/lib/cmake/flatbuffers/FlatbuffersTargets-release.cmake
-- Installing: /usr/local/bin/flatc
-- Installing: /usr/local/lib/cmake/flatbuffers/FlatcTargets.cmake
-- Installing: /usr/local/lib/cmake/flatbuffers/FlatcTargets-release.cmake
Run Code Online (Sandbox Code Playgroud)