如何在OSX上构建Flatbuffers?

6

我正在尝试在OSX上构建flatbuffers,但我不确定该如何确切地进行。根据文档的说法,我应该运行cmake -G "Xcode"。我这样做了,得到了以下结果:

-- The C compiler identification is Clang 5.1.0
-- The CXX compiler identification is Clang 5.1.0
-- Check for working C compiler using: Xcode
-- Check for working C compiler using: Xcode -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Xcode
-- Check for working CXX compiler using: Xcode -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: Temp/flatbuffers

然而,从那里开始我就不知道该怎么做了。我尝试运行make,但是收到了错误消息make: *** No targets specified and no makefile found. Stop.。有什么建议如何构建它吗?

6个回答

14

当你运行 cmake 时,你为 Xcode IDE (可以从 Apple 应用商店下载)生成了一个项目。

如果你想使用 make 进行构建,则使用以下命令:

cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release

之后,

make

应该按预期工作。


12

不需要使用 make 命令,只需在shell中运行以下命令:

$ cmakexbuild

等待执行完成后,您将会在./Debug文件夹中得到 flatc 文件。


8
在OSX系统中,建议使用Homebrew来安装flatbuffer架构编译器。
brew install flatbuffers

用法:使用架构编译器


我不建议这样做。重要的是模式编译器与你使用的库源代码版本相同,因此最好从同一个git仓库构建。 - Aardappel

3

对于Mac-OSX
请确保已在您的计算机上安装了Xcode。如果没有,请执行命令xcode-select --install进行安装。

  1. If you need latest changes download source code from repo or to get source code for a particular version download source from here

  2. cd flatbuffers and execute cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release

    If you encounter error like

    CMake Warning:
      No source or binary directory provided.  Both will be assumed to be the
    same as the current working directory, but note that this warning will
    become a fatal error in future CMake releases.
    
    
    -- The C compiler identification is unknown
    -- The CXX compiler identification is unknown
    CMake Error at CMakeLists.txt:6 (project):
    No CMAKE_C_COMPILER could be found.
    
    CMake Error at CMakeLists.txt:6 (project):
    No CMAKE_CXX_COMPILER could be found.
    
    -- Configuring incomplete, errors occurred!
    
    See also "<sourc-code-path>/flatbuffers-1.12.0/CMakeFiles/CMakeOutput.log".
    See also "<sourc-code-path>/flatbuffers-1.12.0/CMakeFiles/CMakeError.log".
    
    Inside the log file CMakeError.log:
    
    xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
    
    

    then refer this SO thread
    success message is :

    -- Configuring done
    -- Generating done
    -- Build files have been written to: <source-code-path>/standalone/flatbuffers-1.12.0
    
  3. ./FlatBuffers.xcodeproj or open project in xcode

  4. Build and Run project from Xcode UI

  5. cd Debugand you can see all the binaries present.

    enter image description here

  6. If you want flatc to be available globally:
    ln -sf <path>/flatbuffers-1.12.0/Debug/flatc /usr/local/bin/flatc

已在以下系统上进行过验证:
MacOSX:Mojave,版本:10.14.3、10.14.6
Xcode:版本:10.2.1(10E1001)、11.1(11A1027)

注意:确保在项目中使用相同的版本以确保兼容性。
如果不确定选择哪个版本,则可以克隆存储库并进入特定提交并构建。
例如:对于版本1.11,提交版本为bf9eb67a。


2

-1

FlatBuffers在LINUX(Ubuntu 16)上的安装和构建:

  1. 进入根项目文件夹
  2. yarn add flatc
  3. 进入项目的node_modules文件夹
  4. 如果存在flatbuffers文件夹,请删除
  5. 克隆https://github.com/google/flatbuffers.git
  6. 进入flatbuffers文件夹
  7. cmake -G "Unix Makefiles"(需要安装cmake)
  8. make
  9. 返回根项目文件夹
  10. 在package.json文件中的命令路径从“./flatc”更改为“./node_modules/flatbuffers/flatc”

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接