- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Bob for your valiable advice 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are always welcome!
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.