Using C api and library
Hi @panhu 

Could you please provide the steps you have followed and the version of TF used inorder to better understand the issue?

Thanks. Ok，this is my code(Official provided sample code “”c_test.c“”):

#include "include/core/c/c_api.h"
#include "include/core/c/c_api_experimental.h"
#include "include/core/c/common.h"
#include "include/core/c/builtin_op_data.h"

// This file exists just to verify that the above header files above can build,
// link, and run as "C" code.

#ifdef __cplusplus
#error "This file should be compiled as C code, not as C++."
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static void CheckFailed(const char *expression, const char *filename,
                        int line_number) {
    fprintf(stderr, "ERROR: CHECK failed: %s:%d: %s\n", filename, line_number,
            expression);
    fflush(stderr);
    abort();
}

// We use an extra level of macro indirection here to ensure that the
// macro arguments get evaluated, so that in a call to CHECK(foo),
// the call to STRINGIZE(condition) in the definition of the CHECK
// macro results in the string "foo" rather than the string "condition".
#define STRINGIZE(expression) STRINGIZE2(expression)
#define STRINGIZE2(expression) #expression

// Like assert(), but not dependent on NDEBUG.
#define CHECK(condition) \
  ((condition) ? (void)0 \
               : CheckFailed(STRINGIZE(condition), __FILE__, __LINE__))
#define ASSERT_EQ(expected, actual) CHECK((expected) == (actual))
#define ASSERT_NE(expected, actual) CHECK((expected) != (actual))
#define ASSERT_STREQ(expected, actual) \
    ASSERT_EQ(0, strcmp((expected), (actual)))

// Test the TfLiteVersion function.
static void TestVersion(void) {
    const char *version = TfLiteVersion();
    printf("Version = %s\n", version);
    CHECK(version[0] != '\0');
}

static void TestInferenceUsingSignature(void) {
    TfLiteModel* model = TfLiteModelCreateFromFile(
            "tensorflow/lite/testdata/multi_signatures.bin");
    ASSERT_NE(model, NULL);

    TfLiteInterpreterOptions* options = TfLiteInterpreterOptionsCreate();
    ASSERT_NE(options, NULL);
    TfLiteInterpreterOptionsSetNumThreads(options, 2);

    TfLiteInterpreter* interpreter = TfLiteInterpreterCreate(model, options);
    ASSERT_NE(interpreter, NULL);

    // The options can be deleted immediately after interpreter creation.
    TfLiteInterpreterOptionsDelete(options);

    // (optional) Validate signatures
    ASSERT_EQ(TfLiteInterpreterGetSignatureCount(interpreter), 2);
    ASSERT_STREQ(TfLiteInterpreterGetSignatureKey(interpreter, 0), "add");
    ASSERT_STREQ(TfLiteInterpreterGetSignatureKey(interpreter, 1), "sub");

    // Validate signature "add"
    TfLiteSignatureRunner* add_runner =
            TfLiteInterpreterGetSignatureRunner(interpreter, "add");
    ASSERT_NE(add_runner, NULL);
    ASSERT_EQ(TfLiteSignatureRunnerGetInputCount(add_runner), 1);
    ASSERT_STREQ(TfLiteSignatureRunnerGetInputName(add_runner, 0), "x");
    ASSERT_EQ(TfLiteSignatureRunnerGetOutputCount(add_runner), 1);
    ASSERT_STREQ(TfLiteSignatureRunnerGetOutputName(add_runner, 0), "output_0");

    // Resize signature "add" input tensor "x"
    int input_dims[1] = {2};
    ASSERT_EQ(
            TfLiteSignatureRunnerResizeInputTensor(add_runner, "x", input_dims, 1),
            kTfLiteOk);

    // Allocate tensors for signature "add"
    ASSERT_EQ(TfLiteSignatureRunnerAllocateTensors(add_runner), kTfLiteOk);

    // Validate signature "add" input tensor "x"
    TfLiteTensor* input_tensor =
            TfLiteSignatureRunnerGetInputTensor(add_runner, "x");
    ASSERT_NE(input_tensor, NULL);
    ASSERT_EQ(TfLiteTensorType(input_tensor), kTfLiteFloat32);
    ASSERT_EQ(TfLiteTensorNumDims(input_tensor), 1);
    ASSERT_EQ(TfLiteTensorDim(input_tensor, 0), 2);
    ASSERT_EQ(TfLiteTensorByteSize(input_tensor), sizeof(float) * 2);
    ASSERT_NE(TfLiteTensorData(input_tensor), NULL);

    TfLiteQuantizationParams input_params =
            TfLiteTensorQuantizationParams(input_tensor);
    ASSERT_EQ(input_params.scale, 0.f);
    ASSERT_EQ(input_params.zero_point, 0);

    float input[2] = {2.f, 4.f};
    ASSERT_EQ(TfLiteTensorCopyFromBuffer(input_tensor, input, 2 * sizeof(float)),
              kTfLiteOk);
    ASSERT_EQ(TfLiteSignatureRunnerInvoke(add_runner), kTfLiteOk);

    const TfLiteTensor* output_tensor =
            TfLiteSignatureRunnerGetOutputTensor(add_runner, "output_0");
    ASSERT_NE(output_tensor, NULL);
    ASSERT_EQ(TfLiteTensorType(output_tensor), kTfLiteFloat32);
    ASSERT_EQ(TfLiteTensorNumDims(output_tensor), 1);
    ASSERT_EQ(TfLiteTensorDim(output_tensor, 0), 2);
    ASSERT_EQ(TfLiteTensorByteSize(output_tensor), sizeof(float) * 2);
    ASSERT_NE(TfLiteTensorData(output_tensor), NULL);

    TfLiteQuantizationParams output_params =
            TfLiteTensorQuantizationParams(output_tensor);
    ASSERT_EQ(output_params.scale, 0.f);
    ASSERT_EQ(output_params.zero_point, 0);

    float output[2];
    ASSERT_EQ(TfLiteTensorCopyToBuffer(output_tensor, output, 2 * sizeof(float)),
              kTfLiteOk);
    // Verify the result
    ASSERT_EQ(output[0], input[0] + 2.f);
    ASSERT_EQ(output[1], input[1] + 2.f);

    // The signature runner should be deleted before interpreter deletion.
    TfLiteSignatureRunnerDelete(add_runner);
    TfLiteInterpreterDelete(interpreter);
    // The model should only be deleted after destroying the interpreter.
    TfLiteModelDelete(model);
}

static void RunTests(void) {
 //   TestVersion();
    TestInferenceUsingSignature();
//    TestRepeatResizeInputTensor();
//    TestInferenceUsingInterpreter();
}

int main(void) {
    RunTests();
    return 0;
}

My Static library file is compiled with the following command:

Cmake../tensorflow_src/tensorflow/site/c

Cmake -- build- J "

The Header file uses all the Header file in the core. I don't know whether there is a problem or whether there is a complete case reference for the c interface call.

Thanks!
 Hi @panhu, Help me understand your environment... it says you're using windows but you seem to be following *nix instructions.. are you using WSL? if so which version? 1 or 2? If so, which distribution?.. Are you trying to use the .a or .so file or both? Where did you put those files? how did you link them? How did you build the executable? exact steps as if you are writing a bash script is preferred. Thanks! Thank you for your reply. What I would like to know is whether there is a complete relevant case or document, starting from compiling the library file to the end using C for linking and using Hi @panhu, So the answer is complex, it really depends on what exactly you are trying to do, if you answer my questions that help me identify your environment, I am better able to direct you to the right resources. The file types you mentioned highly suggest a *nix environment, but the issue has this listed:

System information
-windows

This highly suggests that you are using WSL but I'm not sure if I'm misunderstanding or if the information was entered incorrectly somehow. It seems like you are using cmake for building the file but does your project use cmake? There's still a lot of ambiguity so for me to help you if you can answer my questions so that I can reduce the space of the problem we are working with will be great. Thanks! Also sometimes in the process of answering the questions, you are able to see the issue yourself. Thank you for your reply.My initial goal was to use the main function in C language code to call tflite on Linux or Windows, which is to use tflite's C interface. Therefore, I would like to know if there are complete related cases Hi @panhu, Can you try using this as an example, make sure it works in your environment then edit it to try what you want to do? https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/examples/minimal 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. Hi:
If my framework is risc-v, does Tensorflow lite support it?? Hi @panhu,

Here are the supported platforms: https://www.tensorflow.org/lite/microcontrollers#supported_platforms

It does seem like there are successful projects with risc-v: https://www.luffca.com/2022/11/tflite-micro-naxriscv/ but I can't find any official documentation that it is supported unless it is a subset of one of those platforms. Thanks, Does tflite-micro have a C interface? Hello @panhu, Yes but documentation/examples are lite: https://www.tensorflow.org/lite/api_docs/c 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/60849">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/60849">No</a>

**System information**
-windows
  if possible):
- TensorFlow Lite in Play windows
- Google Play Services version

**Standalone code to reproduce the issue**
Hi:
    I have compiled tflite's Static library "libtensorflow-lite. a" and "libtensorflowite_c.so" using cmake according to the official document. However, when I introduced this library and used C to call it, the following error occurred: "undefined reference to ` __imp_TfLiteModelCreateFromFile '", undefined reference to`__ IMP_ TfLiteInterpreterOptionsCreate '

Do you know what caused it, or are there any relevant cases

Thanks!
