In a previous question, I described a problem that static member variables of a class did actually have different values for different other classes including them.
Upon further research, I found out that the translation unit containing the class with the static member variable gets compiled to a static library (.a extension). Other translation units (lets call them plugins, I am working in a rather complex framework named ADTF) that get compiled and linked later on include this library.
My question is now: Is it expected that classes in plugin1 and plugin2 get their own myGlobalBool? When I run the program, modifying cMyLibraryClass::myGlobalBool from plugin1 does not change the variable in plugin2. If it is expected, what would I need to do make the variable shared across plugins? Note that I am under linux, some other questions on SO (here, here) seem to point out that for Windows .dlls, this is expected, but otherwise were not helpful for me.
Example of what I'm doing (it is more complex than that and the error might be somewhere else):
myLibrary.h
cMyLibraryClass
{
cMyLibraryClass();
static bool myGlobalBool;
// Other static variables and stuff
}
myLibrary.cpp
include myLibrary.h
bool cMyLibraryClass::myGlobalBool;
cMyLibraryClass::cMyLibraryClass()
{
// Constructor stuff
}
// Other function implementations of cMyLibraryClass
I end up with
libMyLibrary.a
The plugins get linked withthe following options: (I removed the paths and all the other libraries that get included)
Plugin 1:
g++ -o plugin1.plb -shared -Wl,-Bsymbolic -Wl,--no-undefined -shared plugin1.os -lmyLibrary
Plugin 2:
g++ -o plugin2.plb -shared -Wl,-Bsymbolic -Wl,--no-undefined -shared plugin2.os -lmyLibrary
I appreciate any suggestions on what is happening here, I've been trying to understand for 2 days now. If you feel like I forgot to provide some essential information, just ask and I'll try to add it to the question as soon as possible! Thanks :-)
So, the accepted answer was the solution to my problem. Just in case anybody ever has the same problem with ADTF (Automotive Data and Time-Triggered Framework), the solution to this is actually really simple when you know where to look:
In the main SConsript file of your extension, the last line should say something like:
You simple need to change static to false. Afterwards, go into build/[linux, win]/[release, debug]/$yourextensionname and delete everything in there. Also delete any remaining .a files in your extension folder, and then rebuild from scratch. That's it :-)
Question:
Make
myLibrary
a dynamic library (.so) instead of a static library (.a).