简体   繁体   中英

How to build flatbuffers on OSX?

I'm trying to build flatbuffers on OSX but I'm not sure how to proceed exactly. According to the doc . I should run cmake -G "Xcode" . I did that and got the result:

-- 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

However from there I'm not sure what to do. I've tried to run make but got the error message make: *** No targets specified and no makefile found. Stop. make: *** No targets specified and no makefile found. Stop. . Any idea how to build it?

Instead make , just run following command in the shell:

$ cmakexbuild

After it finish you will get flatc in ./Debug folder.

When you ran cmake, you generated a project for the Xcode IDE (downloadable from the Apple app store).

If you want to build using make, use this command instead:

cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release

After that,

make

should work as intended.

On OSX it's recommended to use Homebrew to install the flatbuffer schema compiler.

brew install flatbuffers

Usage: Using the schema compiler

Follow the below steps to compile the flatbuffer code

For Mac-OSX
Make sure Xcode is already installed in your machine. If not, install it by executing command 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 Debug and you can see all the binaries present.

    在此处输入图片说明

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

Tried and Tested on
MacOSX: Mojave, version: 10.14.3, 10.14.6
Xcode: Version: 10.2.1(10E1001), 11.1(11A1027)

Note: Make sure you use the same version in a project for compatibility.
If you are not sure which version to pick, then you can clone the repo and go to a specific commit and build.
For eg For version 1.11, Commit version is bf9eb67a.

FlatBuffers for LINUX(Ubuntu 16) install and build:

  1. cd root project folder
  2. yarn add flatc
  3. cd node_modules of project
  4. rm flatbuffers folder(if exist)
  5. git clone https://github.com/google/flatbuffers.git
  6. cd flatbuffers
  7. cmake -G "Unix Makefiles" (install cmake if need)
  8. make
  9. cd root project folder
  10. change path in command in package.json file from "./flatc" to "./node_modules/flatbuffers/flatc"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM