Skip to main content
Visitor II
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;
    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello,

    Declare int i as static:

    static int i;

     

     

    2 replies

    mƎALLEmAnswer
    Technical Moderator
    February 21, 2025

    Hello,

    Declare int i as static:

    static int i;