/tmp/ccblPtfK.o:(.bss+0x0): multiple definition of `users'
/tmp/ccR62VWy.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
After some research, I found out that header files are meant for variable declaration only. I changed it to: Abcd users[];
But here is when I am stumped. If I leave the array size empty, that means that I will have to define it in both .cpp files, which will result in the 'multiple definition' error too.
You need to have header guards and / or #pragma once these will stop the file being included more than once.
1 2 3 4 5 6 7 8 9 10 11
#pragma once // not standard, but has wide support, does a better job than humans
#ifndef MAIN_H
#define MAIN_H
struct Abcd
{
//do something here
};
Abcd users[50];
#endif
But that's really a bad idea, since it can leads to subtle errors very difficult to discover.
It should be far, far better if you:
1) avoided C-style array and used std::vector (or std::array, if you are sure about dimension)
2) passed the array/vector/whatever as a parameter between functions instead of declaring it globally.
Include guards / header guards, call them as you prefer, won't be of any help in this situation, since every translation unit is compiled before being linked, i.e. include guards protect you from including twice the same file from the same translation unit, not when you are linking to other files.