TensorflowLite C API not linking with TensorflowLite_Flex delegate (Automatically or manually)
@SagaraBattousai Could you please make sure that Flex delegate was built correctly, you may use the following command to check it;
```
bazel build -c opt --config=monolithic tensorflow/lite/delegates/flex:tensorflowlite_flex
```
Please let us know? Thank you! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62227">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62227">No</a>
 ```C++
#include <fstream>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector> 
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/optional_debug_tools.h"
#include "tensorflow/lite/core/c/c_api.h"
#include "tensorflow/lite/core/c/c_api_experimental.h"
#include "tensorflow/lite/core/c/builtin_op_data.h" 
#include "tensorflow/lite/core/c/c_api_opaque.h"
#include "tensorflow/lite/core/c/c_api_types.h"
#include "tensorflow/lite/core/c/common.h"

#include <Windows.h>
#define TFLITE_MINIMAL_CHECK(x)                              \
  if (!(x)) {                                                \
    fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); \
    exit(1);                                                 \
  }
   TfLiteModel* model = TfLiteModelCreateFromFile(model_path.c_str());
    TFLITE_MINIMAL_CHECK(model != nullptr);

    TfLiteInterpreterOptions* options = TfLiteInterpreterOptionsCreate();
    TfLiteInterpreter* interpreter = TfLiteInterpreterCreate(model, options);
    TFLITE_MINIMAL_CHECK(interpreter != nullptr);
    TfLiteInterpreterOptionsDelete(options);
    auto hdll = LoadLibrary("tensorflowlite_flex.dll");
    
    auto TF_AcquireFlexDelegate = reinterpret_cast<tflite::Interpreter::TfLiteDelegatePtr(*)()>(GetProcAddress(hdll, "TF_AcquireFlexDelegate"));
    if (TF_AcquireFlexDelegate == NULL) {
        std::cout << "TF_AcquireFlexDelegate couldn't be run" << std::endl;
    }
     
    auto delegate = TF_AcquireFlexDelegate();
    auto TfLiteStatus = TfLiteInterpreterModifyGraphWithDelegate(interpreter, delegate.get());
    if(TfLiteStatus==0)
    std::cout << "ModifyGraphWithDelegate Ok" << std::endl;
```
I have utilized the C API provided in c_api_experimental.h to link the TensorflowLite Flex delegate.
### System information

-   **Have I written custom code (as opposed to using a stock example script
    provided in TensorFlow)**:
-   **OS Platform and Distribution**: Windows 11
-   **Mobile device**: Additionally happens on Android 14 Pixel 7a
-   **TensorFlowLite installed from (source or binary)**: C API build with CMake and Tensorflowlite_flex built with bazel
-   **TensorFlow version (use command below)**: 2.14
-   **Bazel version (if compiling from source)**: Bazelisk version: v1.18.0
-   **GCC/Compiler version (if compiling from source)**: Visual Studio 17.7.4
-   **CUDA/cuDNN version**: N/A
-   **GPU model and memory**: N/A
-   **Exact command to reproduce**: N/A

Using Cmake To build and link the TensorflowLite C API Works perfectly with any tflite model signature not using Flex operators. However, after linking the C API with tensorflowlite_flex, using the following as part of a CMakeLists.txt:
```cmake
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  set_target_properties(tensorflowlite_c PROPERTIES 
    IMPORTED_LOCATION_DEBUG "${TFLITE_ROOT}/lib/windows/Debug/tensorflowlite_c.dll"
    IMPORTED_IMPLIB_DEBUG "${TFLITE_ROOT}/lib/windows/Debug/tensorflowlite_c.lib"

    IMPORTED_LOCATION_RELEASE "${TFLITE_ROOT}/lib/windows/Release/tensorflowlite_c.dll"
    IMPORTED_IMPLIB_RELEASE "${TFLITE_ROOT}/lib/windows/Release/tensorflowlite_c.lib"
    )

  set_target_properties(tensorflowlite_flex PROPERTIES 
    IMPORTED_LOCATION "${TFLITE_ROOT}/lib/windows/tensorflowlite_flex.dll"
    IMPORTED_IMPLIB "${TFLITE_ROOT}/lib/windows/tensorflowlite_flex.dll.if.lib"
    )
  target_link_libraries(tensorflowlite_c INTERFACE tensorflowlite_flex)
endif()
```  
, the running process outputs: ERROR: Select TensorFlow op(s), included in the given model, is(are) not supported by this interpreter. Make sure you apply/link the Flex delegate before inference.

My final approach was to use (what I guessed) was the auto linking code that exists in the C++ code (namely:
```cpp
auto hdll = LoadLibrary("tensorflowlite_flex.dll");

auto flex_fp = reinterpret_cast<TfLiteDelegatePtr(*)()>(
    GetProcAddress(hdll, "TF_AcquireFlexDelegate"));
if (flex_fp == NULL) {
  throw std::runtime_error("flex_fp couldn't be run");
}

flex_ = flex_fp(); // flex_ is a member (not shown here) // This line gets the message: INFO: Created TensorFlow Lite delegate for select TF ops.

TfLiteInterpreterOptionsAddDelegate(options_.get(), flex_.get()); // *THIS* is the important line

```
). If the final line is commented out we get the nice INFO message that the delegate has been created but end up with the same warning message. Alternatively, if the last line is included we get an invalid memory access exception. 

I am going to switch to the C++ API for tensorflow lite and see if that works as I am under a tight deadline but any help would be much appreciated as the stable ABI for the C API is far better for my PhD.


Additionally, I built "tensorflow/lite/delegates/flex:delegate" with bazelisk (bazel v1.18.0) but (after waiting an extremely long time for it to compile) I cannot track down what it built and did not change anything.


(Note, some small changes to CMakeFiles were required to build tensorflowlite_c.dll and the exact binary I have used can be obtained from [here](https://github.com/SagaraBattousai/tflite-clib-builder/releases/download/v1.0.1/tensorflowlite_c-winx64-Android.zip) )



