cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple definition of ***

Chlaban
Associate
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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
mƎALLEm
ST Employee

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.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

View solution in original post

2 REPLIES 2
AScha.3
Chief III
mƎALLEm
ST Employee

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.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.