Skip to main content
Associate
February 21, 2025
Solved

Multiple definition of ***

  • February 21, 2025
  • 2 replies
  • 472 views

Hello,
I have a question that is completely unrelated to STM, but I believe you can help me.
I would like to advise why I cannot use the following code and the message multiple definition comes out.
I will reduce the code to the necessary minimum.
I thought local variables in files only have local effect, can someone explain this to me?

Thank you


main:
#include "A.h"
#include "B.h"
void main()
{}

A.h:
---------
A.c:
#include "A.h"
int i;
----------

B.h:
----------
B.c:
#include "B.h"
int i;
Best answer by mƎALLEm

Hello,

Declare int i as static:

static int i;

 

 

2 replies

AScha.3
Super User
February 21, 2025
mƎALLEm
mƎALLEmBest answer
Technical Moderator
February 21, 2025

Hello,

Declare int i as static:

static int i;

 

 

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."