6

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.. Any idea how to build it?

laurent
  • 88,262
  • 77
  • 290
  • 428

6 Answers6

14

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.

Aaron
  • 666
  • 1
  • 7
  • 23
Aardappel
  • 5,559
  • 1
  • 19
  • 22
12

Instead make, just run following command in the shell:

$ cmakexbuild

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

pepyakin
  • 2,217
  • 19
  • 31
8

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

brew install flatbuffers

Usage: Using the schema compiler

Parav01d
  • 308
  • 2
  • 5
  • I would not recommend that. It is important the schema compiler is the same version as the library source you use with it, so best to all build from the same git repo. – Aardappel Jan 12 '19 at 16:19
3

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

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 e.g. For version 1.11, Commit version is bf9eb67a.

dkb
  • 4,389
  • 4
  • 36
  • 54
2

Follow the below steps to compile the flatbuffer code

Brijesh Masrani
  • 1,439
  • 3
  • 16
  • 27
-1

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"