I have a .h file
test.h
std::list<std::string> RegisterList;
I want to access this list in 2 .c files
A.c
#include "test.h"
RegisterList.push_back(myString);
B.c
#include "test.h"
RegisterList.push_back(myString2);
When i compile this code, i get an error ld: fatal: symbol `RegisteredList' is multiply-defined:
What can be the problem ? Is RegsiterList is initialized by default in test.h which is leading to this problem ?
Because you defined the object in the header file and violated one definition rule. Never define objects in header file.
If you want to use a global object, You need to declare it as extern and define it in one and only one source file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With