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.