Home | History | Annotate | Download | only in source
      1 Building    {#flatbuffers_guide_building}
      2 ========
      3 
      4 ## Building with CMake
      5 
      6 The distribution comes with a `cmake` file that should allow
      7 you to build project/make files for any platform. For details on `cmake`, see
      8 <http://www.cmake.org>. In brief, depending on your platform, use one of
      9 e.g.:
     10 
     11     cmake -G "Unix Makefiles"
     12     cmake -G "Visual Studio 10"
     13     cmake -G "Xcode"
     14 
     15 Then, build as normal for your platform. This should result in a `flatc`
     16 executable, essential for the next steps.
     17 Note that to use clang instead of gcc, you may need to set up your environment
     18 variables, e.g.
     19 `CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake -G "Unix Makefiles"`.
     20 
     21 Optionally, run the `flattests` executable from the root `flatbuffers/`
     22 directory to ensure everything is working correctly on your system. If this
     23 fails, please contact us!
     24 
     25 Building should also produce two sample executables, `flatsamplebinary` and
     26 `flatsampletext`, see the corresponding `.cpp` files in the
     27 `flatbuffers/samples` directory.
     28 
     29 *Note that you MUST be in the root of the FlatBuffers distribution when you
     30 run 'flattests' or `flatsampletext`, or it will fail to load its files.*
     31 
     32 ## Building for Android
     33 
     34 There is a `flatbuffers/android` directory that contains all you need to build
     35 the test executable on android (use the included `build_apk.sh` script, or use
     36 `ndk_build` / `adb` etc. as usual). Upon running, it will output to the log
     37 if tests succeeded or not.
     38 
     39 You may also run an android sample from inside the `flatbuffers/samples`, by
     40 running the `android_sample.sh` script. Optionally, you may go to the
     41 `flatbuffers/samples/android` folder and build the sample with the
     42 `build_apk.sh` script or `ndk_build` / `adb` etc.
     43 
     44 ## Using FlatBuffers in your own projects.
     45 
     46 For C++, there is usually no runtime to compile, as the code consists of a
     47 single header, `include/flatbuffers/flatbuffers.h`. You should add the
     48 `include` folder to your include paths. If you wish to be
     49 able to load schemas and/or parse text into binary buffers at runtime,
     50 you additionally need the other headers in `include/flatbuffers`. You must
     51 also compile/link `src/idl_parser.cpp` (and `src/idl_gen_text.cpp` if you
     52 also want to be able convert binary to text).
     53 
     54 To see how to include FlatBuffers in any of our supported languages, please
     55 view the [Tutorial](@ref flatbuffers_guide_tutorial) and select your appropriate
     56 language using the radio buttons.
     57 
     58 #### For Google Play apps
     59 
     60 For applications on Google Play that integrate this library, usage is tracked.
     61 This tracking is done automatically using the embedded version string
     62 (flatbuffer_version_string), and helps us continue to optimize it.
     63 Aside from consuming a few extra bytes in your application binary, it shouldn't
     64 affect your application at all. We use this information to let us know if
     65 FlatBuffers is useful and if we should continue to invest in it. Since this is
     66 open source, you are free to remove the version string but we would appreciate
     67 if you would leave it in.
     68