Notification texts go here Contact Us Buy Now!

"Multiple definition of" Error in ESP-IDF

In C/C++, a variable can be defined only once within a program. If the same variable is defined multiple times, it will result in a "multiple definition" error. In ESP-IDF, this error can occur when a variable is declared in a header file and included in multiple source files.

To resolve this issue, you should declare the variable in the header file and define it in exactly one source file. Here's an example:

#ifndef _TEST_H_ #define _TEST_H_ struct SomeData { float x; }; // Declare the variable in the header file extern struct SomeData someData; void something(void); #endif
#include "test.h" // Define the variable in one source file struct SomeData someData; void something(void){ someData.x = 35; }
By following this approach, you can avoid the "multiple definition" error and ensure that the variable is defined only once in your program.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.