如何在Linux Ubuntu上安装Flatc和FlatBuffers

时间:2019-03-28 09:48:49

标签: linux ubuntu flatbuffers

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

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

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

4 个答案:

答案 0 :(得分:1)

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

要使用cmake从源代码构建和安装所有平面缓冲区,请按照说明here

  • 克隆repocd flatbuffers
  • 为linux ubuntu生成构建文件
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
  • 编译
make
  • 安装
sudo make install
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

答案 1 :(得分:1)

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

sudo apt update
sudo apt install -y flatbuffers-compiler

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

sudo apt-add-repository ppa:hnakamur/flatbuffers
sudo apt update
sudo apt install -y flatbuffers-compiler

两者都比较老(1.11),但是如果您不使用最新功能,则应该非常可靠。

答案 2 :(得分:0)

用于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. sudo ln -s /全路径到flatbuffer / flatbuffers / flatc / usr / local / bin / flatc
  8. chmod + x / full-path-to-flatbuffer / flatbuffers / flatc
  9. 在任何地方以“ flatc”运行

答案 3 :(得分:0)

这是使生活变得轻松的 CMake 文件。这些 cmake 命令将从 git repo 下载 flatbuffer 并安装在 linux 系统范围内访问。要在构建后安装,请运行“sudo make install”。

-----------将以下内容保存到CMakeLists.txt文件中并运行cmake-----------

cmake_minimum_required(VERSION 3.11)
cmake_policy(SET CMP0048 NEW)

project(flatbuffers-external
    VERSION 2.0.0
    DESCRIPTION "Flatbuffers Build"
)

option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." OFF)
option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
       OFF)
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
       OFF)
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" OFF)


include(FetchContent)
FetchContent_Declare(
    flatbuffers_cpp
    GIT_REPOSITORY  https://github.com/google/flatbuffers.git
    GIT_TAG         v2.0.0
    PREFIX            "${PROJECT_SOURCE_DIR}/tp"
    SOURCE_DIR        "${PROJECT_SOURCE_DIR}/tp/fb"
    BINARY_DIR        "${PROJECT_SOURCE_DIR}/tp/fb-build"
)

FetchContent_MakeAvailable(flatbuffers_cpp)