Search code examples
c++visual-studiooptimizationgoogleteststatic-variables

How to avoid for c++ compiler optimizer to remove static variable code?


I use C++ in MS Visual Studio C++ 2013 sp5. As you know, google test(gtest) initialize test codes as static variables. When I put these gtest codes (.cpp) in main project, there is no problem. But, when I move these gtest codes (.cpp) to library project which main project depends, gtest don't work. I can't put breakpoint as if there is no code. (BreakPoint point looks like white circle not red circle). I guess compiler optimizer omit these static variables code in cpp because these variables are references nowhere. But, it's constructor do something so I don't understand why compiler remove or doesn't make code for these static variables.

How to prevent these situation? Is there any options for that? Or any knowhow?


Solution

  • Turn 'Link Library Dependencies' and 'Use Library Dependency Inputs' into Yes then compiler make codes. It works. C++ static variable in .lib does not initialize force visual studio to link all symbols in a lib file