Move AppManager::getEnabledApps_ to a .cpp file to prevent multiple definitions#170
Move AppManager::getEnabledApps_ to a .cpp file to prevent multiple definitions#170bdutro-mips wants to merge 2 commits intosparcians:mainfrom
Conversation
|
I need to understand how to repro this myself, as it's not obvious to me what's going on. Static methods / local static variables in methods in header files is a common thing. What's the minimum I need to reproduce this? I'm guessing there are build/linker steps involved that I am not thinking of. Side note: I've tried very hard to keep SimDB as a header-only library, and I want to keep it that way. I'm doubting that we need a full .cpp file just for this. Are you using the installed Sparta in the conda env sparta2? |
|
Repro instructions:
Here's the error message:
|
|
I've tested this with these Clang and GCC versions and get the same problem every time:
|
|
I'll also note that this bug shows up in some executables but not others - I think Clang is making different inlining decisions that affect whether the duplicate symbol shows up and/or whether it's a problem. |
|
Let's wait until the tree node extensions redesign gets into map_v2.1 and try this again. But I'm 99% sure that this has nothing to do with SimDB specifically -- the use of SPARTA_SEARCH_DIR combined with Conda is broken. I'm of the opinion that SPARTA_SEARCH_DIR should not be used for our internal simulators, and they all should build Sparta from source, OR they can only use an "official" Sparta install in Conda. So like this:
Which will do the local When I tried your repro steps using a debug build, even with a map_v2.1 install in /home/cnyce/map-brett, when I step through the code it gets into source files in $CONDA_PREFIX. So we either need to figure out the real way to do SPARTA_SEARCH_DIR or remove it and build Sparta from source. Mixing-and-matching compilers for Sparta and downstream simulators is not helping either -- yet another reason to build from source. |
Yeah, you have to override quite a few CMake variables to get it to ignore any centrally installed Sparta builds. However I also reproduced this bug on systems with no Conda install and no global Sparta. |
Yeah, if we want to advertise Sparta as a truly packageable library then we need to get this fixed, but I'm also ok with building from source every time (it doesn't take that long to build compared to the simulators that use it). |
|
I fixed this and merged it in: In the short term, we'll just use these non-static apis. In the longer term, I have a design for a real plugin system using shared libraries that won't have any static registration / static apis. But this quick workaround will do for now. I'm going to update Sparta to use this new stuff and add the changes to my larger open PR for tree node extensions. Then I'll make any changes needed for internal simulators after that. |
I ran into an issue trying to compile our internal simulator with clang and link it against a Sparta + SimDB compiled with GCC. Clang was instantiating its own instance of
AppManager::getEnabledApps_because it was present in the header and not linking against the instance inlibsparta.a.It seems that the singleton pattern requires the static instance to live in a single translation unit to guarantee that it works correctly across linkers.
I threw this together quickly, so let me know if the CMake config needs any changes.