<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>MCX MicrocontrollersのトピックRe: How to Integrate a C++ TFLite Model into a C-Based MCUXpresso Project?</title>
    <link>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Integrate-a-C-TFLite-Model-into-a-C-Based-MCUXpresso/m-p/2394693#M5636</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/262607"&gt;@sivamankomb&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for your post.&lt;/P&gt;
&lt;P&gt;Of course you &lt;SPAN&gt;can&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;mix C and C++ source files in an MCUXpresso project.&amp;nbsp;In fact, this is also the approach used in our SDK demos. For reference, you can review several eIQ-related example projects included in the SDK. The SDK is available for download from &lt;A href="https://mcuxpresso.nxp.com/select" target="_blank"&gt;Select Board | MCUXpresso SDK Builder&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Celeste_Liu_0-1784012914332.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/392183i2A913368AEA86BFF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Celeste_Liu_0-1784012914332.png" alt="Celeste_Liu_0-1784012914332.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The key points are as follows:&lt;/P&gt;
&lt;P&gt;- .c files are compiled as C code.&lt;BR /&gt;- .cpp files are compiled as C++ code.&lt;BR /&gt;- The final linking stage must use a toolchain that supports the C++ runtime and C++ symbol resolution.&lt;BR /&gt;- C code should only call functions exposed through extern "C" wrappers and should not directly include or use TFLM C++ classes, templates, or namespaces.&lt;/P&gt;
&lt;P&gt;Therefore, the recommended approach is to encapsulate the TFLM inference implementation in a .cpp file and expose only a C ABI-compatible wrapper interface to the C application.&lt;BR /&gt;For example, in the SDK's tflm_label_image demo, the core TFLM inference logic is implemented in common/tflm/model.cpp. This file uses the TFLM C++ APIs, such as&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/micro_op_resolver.h"

static const tflite::Model* s_model = nullptr;
static tflite::MicroInterpreter* s_interpreter = nullptr;
extern tflite::MicroOpResolver &amp;amp;MODEL_GetOpsResolver();&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Then creating a tflite::MicroInterpreter instance and calling AllocateTensors() within MODEL_Init() to perform initialization.&lt;/P&gt;
&lt;P&gt;The externally exposed model.h,&amp;nbsp; provides a C-friendly interface. &lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#if defined(__cplusplus)
extern "C" {
#endif

status_t MODEL_Init(void);
uint8_t* MODEL_GetInputTensorData(tensor_dims_t* dims, tensor_type_t* type);
uint8_t* MODEL_GetOutputTensorData(tensor_dims_t* dims, tensor_type_t* type);
void MODEL_ConvertInput(uint8_t* data, tensor_dims_t* dims, tensor_type_t type);
status_t MODEL_RunInference(void);
const char* MODEL_GetModelName(void);

#if defined(__cplusplus)
}
#endif&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;The function declarations are exported through extern "C", allowing C source files to simply #include "model.h" and call functions such as MODEL_Init() and MODEL_RunInference() without needing any knowledge of C++ types like tflite::MicroInterpreter or MicroMutableOpResolver.&lt;BR /&gt;This architecture is also the approach adopted by our SDK examples and is generally recommended when integrating TFLM into a C-based application, as it cleanly isolates the C++ implementation details while preserving a pure C interface for the application layer.&lt;/P&gt;
&lt;P&gt;If you want to integrate customer ML model to SDK demo, you can refer to&amp;nbsp;&lt;A href="https://www.nxp.com/webapp/Download?colCode=AN14241&amp;amp;location=null" target="_blank"&gt;AN14241&lt;/A&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Celeste&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jul 2026 07:26:50 GMT</pubDate>
    <dc:creator>Celeste_Liu</dc:creator>
    <dc:date>2026-07-14T07:26:50Z</dc:date>
    <item>
      <title>How to Integrate a C++ TFLite Model into a C-Based MCUXpresso Project?</title>
      <link>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Integrate-a-C-TFLite-Model-into-a-C-Based-MCUXpresso/m-p/2394072#M5628</link>
      <description>&lt;P&gt;Hello NXP Team,&lt;/P&gt;&lt;P&gt;I am integrating a TensorFlow Lite Micro model into my MCUXpresso project for the MCXN947. My application is written in C, while the TensorFlow Lite Micro inference code and generated model are in C++.&lt;/P&gt;&lt;P&gt;I am encountering compilation and linking issues when combining the C and C++ source files. I have already tried using "extern C", but the issue remains.&lt;/P&gt;&lt;P&gt;Could you please advise on the following?&lt;/P&gt;&lt;P&gt;Is it recommended to mix C and C++ source files in an MCUXpresso project?&lt;/P&gt;&lt;P&gt;What is the recommended approach for integrating a C++ TensorFlow Lite Micro model into a C-based application?&lt;/P&gt;&lt;P&gt;Are there any required compiler/linker settings or reference examples for this integration?&lt;/P&gt;&lt;P&gt;Any guidance would be greatly appreciated. Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jul 2026 15:43:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Integrate-a-C-TFLite-Model-into-a-C-Based-MCUXpresso/m-p/2394072#M5628</guid>
      <dc:creator>sivamankomb</dc:creator>
      <dc:date>2026-07-12T15:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to Integrate a C++ TFLite Model into a C-Based MCUXpresso Project?</title>
      <link>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Integrate-a-C-TFLite-Model-into-a-C-Based-MCUXpresso/m-p/2394693#M5636</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/262607"&gt;@sivamankomb&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for your post.&lt;/P&gt;
&lt;P&gt;Of course you &lt;SPAN&gt;can&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;mix C and C++ source files in an MCUXpresso project.&amp;nbsp;In fact, this is also the approach used in our SDK demos. For reference, you can review several eIQ-related example projects included in the SDK. The SDK is available for download from &lt;A href="https://mcuxpresso.nxp.com/select" target="_blank"&gt;Select Board | MCUXpresso SDK Builder&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Celeste_Liu_0-1784012914332.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/392183i2A913368AEA86BFF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Celeste_Liu_0-1784012914332.png" alt="Celeste_Liu_0-1784012914332.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The key points are as follows:&lt;/P&gt;
&lt;P&gt;- .c files are compiled as C code.&lt;BR /&gt;- .cpp files are compiled as C++ code.&lt;BR /&gt;- The final linking stage must use a toolchain that supports the C++ runtime and C++ symbol resolution.&lt;BR /&gt;- C code should only call functions exposed through extern "C" wrappers and should not directly include or use TFLM C++ classes, templates, or namespaces.&lt;/P&gt;
&lt;P&gt;Therefore, the recommended approach is to encapsulate the TFLM inference implementation in a .cpp file and expose only a C ABI-compatible wrapper interface to the C application.&lt;BR /&gt;For example, in the SDK's tflm_label_image demo, the core TFLM inference logic is implemented in common/tflm/model.cpp. This file uses the TFLM C++ APIs, such as&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/micro_op_resolver.h"

static const tflite::Model* s_model = nullptr;
static tflite::MicroInterpreter* s_interpreter = nullptr;
extern tflite::MicroOpResolver &amp;amp;MODEL_GetOpsResolver();&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Then creating a tflite::MicroInterpreter instance and calling AllocateTensors() within MODEL_Init() to perform initialization.&lt;/P&gt;
&lt;P&gt;The externally exposed model.h,&amp;nbsp; provides a C-friendly interface. &lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#if defined(__cplusplus)
extern "C" {
#endif

status_t MODEL_Init(void);
uint8_t* MODEL_GetInputTensorData(tensor_dims_t* dims, tensor_type_t* type);
uint8_t* MODEL_GetOutputTensorData(tensor_dims_t* dims, tensor_type_t* type);
void MODEL_ConvertInput(uint8_t* data, tensor_dims_t* dims, tensor_type_t type);
status_t MODEL_RunInference(void);
const char* MODEL_GetModelName(void);

#if defined(__cplusplus)
}
#endif&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;The function declarations are exported through extern "C", allowing C source files to simply #include "model.h" and call functions such as MODEL_Init() and MODEL_RunInference() without needing any knowledge of C++ types like tflite::MicroInterpreter or MicroMutableOpResolver.&lt;BR /&gt;This architecture is also the approach adopted by our SDK examples and is generally recommended when integrating TFLM into a C-based application, as it cleanly isolates the C++ implementation details while preserving a pure C interface for the application layer.&lt;/P&gt;
&lt;P&gt;If you want to integrate customer ML model to SDK demo, you can refer to&amp;nbsp;&lt;A href="https://www.nxp.com/webapp/Download?colCode=AN14241&amp;amp;location=null" target="_blank"&gt;AN14241&lt;/A&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Celeste&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2026 07:26:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCX-Microcontrollers/How-to-Integrate-a-C-TFLite-Model-into-a-C-Based-MCUXpresso/m-p/2394693#M5636</guid>
      <dc:creator>Celeste_Liu</dc:creator>
      <dc:date>2026-07-14T07:26:50Z</dc:date>
    </item>
  </channel>
</rss>

