# CMake build Tensorflow Lite with Flex

**URL:** <https://discuss.ai.google.dev/t/cmake-build-tensorflow-lite-with-flex/32076>\
**Category:** General Discussion\
**Tags:** tflite, help\_request\
**Created:** [September 22, 2022, 1:23am UTC](https://discuss.ai.google.dev/t/cmake-build-tensorflow-lite-with-flex/32076 "2022-09-22T01:23:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mymind1919](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mymind1919/32/12086_2.png) [@mymind1919](https://discuss.ai.google.dev/u/mymind1919)\
**Post date:** [September 22, 2022, 1:23am UTC](https://discuss.ai.google.dev/t/cmake-build-tensorflow-lite-with-flex/32076/1 "2022-09-22T01:23:39Z")

</div>

Hi, I want to run simple conv2d layer training using C++ API of TF Lite. I’ve used `examples/minimal` project as reference. Calling `trainer->invoke()` leads to next error:

> ERROR: TensorFlow Lite Error: Select TensorFlow op(s), included in the given model is(are) not supported by this interpreter. Make sure you apply/link Flex delegate before inference. For the Android, it can be resolved by adding “org.tensorflow:tensorflow-lite-select-tf-ops” dependency…

> ERROR: Node number 48 (FlexConv2DBackpropFilter) failed to prepare.

I didn’t find any good tutorial on Flex delegate. Please, tell me, how to build TF Lite with Flex using CMake and how to make this interpreter use Flex’s implementation of this node. Thanks

---

<div class="post-metadata">

**Author:** ![dhruvkakadiya](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/dhruvkakadiya/32/11257_2.png) [@dhruvkakadiya](https://discuss.ai.google.dev/u/dhruvkakadiya)\
**Post date:** [September 26, 2022, 2:50am UTC](https://discuss.ai.google.dev/t/cmake-build-tensorflow-lite-with-flex/32076/4 "2022-09-26T02:50:40Z")

</div>

@mymind1919 I have been trying to achieve same thing and on Mac os, I am able to link and generate correct binary/executable by using below sample cmake snippet.

To build required libraries…

```auto
bazel build -c opt --config=monolithic tensorflow/lite:libtensorflowlite
bazel build -c opt --config=monolithic tensorflow/lite:libtensorflowlite_flex

```

Assuming binary file name is inference.cpp and then need to link these libraries.

1. tensorflowlite
2. tensorflowlite\_flex

```auto
add_executable(inference inference.cpp)
target_link_libraries(inference tensorflowlite tensorflowlite_flex)

```

That enables Flex delegate support for Mac OS but same thing doesn’t work when I am trying to build it for ARM.

---

<div class="post-metadata">

**Author:** ![chunduriv](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@chunduriv](https://discuss.ai.google.dev/u/chunduriv)\
**Post date:** [November 22, 2022, 11:14am UTC](https://discuss.ai.google.dev/t/cmake-build-tensorflow-lite-with-flex/32076/6 "2022-11-22T11:14:27Z")

</div>

Can you please try [–no-as-needed option](https://github.com/tensorflow/tensorflow/issues/55536#issuecomment-1262358520) and let us know?

---

<div class="post-metadata">

**Author:** ![lenny\_burkdoll](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/lenny_burkdoll/32/12966_2.png) [@lenny\_burkdoll](https://discuss.ai.google.dev/u/lenny_burkdoll)\
**Post date:** [December 1, 2022, 11:42am UTC](https://discuss.ai.google.dev/t/cmake-build-tensorflow-lite-with-flex/32076/8 "2022-12-01T11:42:53Z")

</div>

Step 1. Install CMake tool  
It requires CMake 3.16 or higher. On Ubuntu, you can simply run the following command.  
sudo apt-get install cmake  
Or you can follow the official cmake installation guide  
Step 2. Clone TensorFlow repository  
git clone [GitHub - tensorflow/tensorflow: An Open Source Machine Learning Framework for Everyone](https://github.com/tensorflow/tensorflow.git) tensorflow\_src  
Note: If you’re using the TensorFlow Docker image, the repo is already provided in /tensorflow\_src/.  
Step 3. Create CMake build directory

mkdir tflite\_build  
cd tflite\_build  
Step 4. Run CMake tool with configurations  
Release build  
It generates an optimized release binary by default. If you want to build for your workstation, simply run the following command.

cmake …/tensorflow\_src/tensorflow/lite
