the command 'arm-none-eabi-gcc.exe' failed with exit code '1'

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 Hello everybody,

   

i've a problem that i managed to solve, but i couldn't understand whey the solution worked.

   

when i build my project i get this error 

   

the command 'arm-none-eabi-gcc.exe' failed with exit code '1'

   

When i checked the output window i found this build error

   

multiple definition of `MY_FoundObserver'

   

 

   

I have 3 files main.c, my_ble.c, and my_ble.h

   

I used the following at the beginning of the header file to avoid any redefinitions

   

 #ifndef MY_BLE_H

   

#define MY_BLE_H

   

#define FALSE (0u)

   

uint8 MY_FoundObserver = FALSE;

   

......

   

#endif

   
     The solution:   
   
    after several hours and trying everything even non-logical solutions, i found that the reason was   
   
     uint8 MY_FoundObserver = FALSE;   
   
        
   
    When i write it as   
   
     uint8 MY_FoundObserver ;   
   
    everything goes fine.   
   
        
   
    Can anyone tell me the reason behind this? why the initialization made this problem?   
   
        
   
    Thanks   
0 Likes
6 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I can see no reason behind that, but i cannot reproduce that error either. Can you post a project that shows that strange behaving? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.



Bob
 

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

 Thanks Bob

   

The file is attached

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

It should not lead to an error, but you did something you strictly should avoid: You defined (allocate space) a variable in a .h-file.

   

Usually you only declare (announce that a declaration will follow) a variable here which forbids an initialization at this point.

   

Best practice: in .h file

   

extern uint8 My_FoundObserver; // Declaration, no memory is allocated here
and in your .c file

   

uint8 My_FoundObserver = FALSE; // Definition

   

Same applies to your counter variable

   

 

   

And something I use for my boolean constants:

   

#define FALSE 0      //  This conforms with C-language if, while etc

   

#define TRUE !FALSE    // Tribute to Mr. Boole

   

 

   

Bob
 

0 Likes
Anonymous
Not applicable

Thanks Bob for your valiable advice 🙂

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You are always welcome!

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

I think thats correct.  If you include that header file from multiple C files, you get really multiple definitions for the same variable. And then the linker complains about it, because it cannot tell which one to use.

0 Likes