[英]How to avoid for c++ compiler optimizer to remove static variable code?
I use C++ in MS Visual Studio C++ 2013 sp5. 我在MS Visual Studio C ++ 2013 sp5中使用C ++。 As you know, google test(gtest) initialize test codes as static variables.
如您所知,google test(gtest)将测试代码初始化为静态变量。 When I put these gtest codes (.cpp) in main project, there is no problem.
当我将这些gtest代码(.cpp)放在主项目中时,没有问题。 But, when I move these gtest codes (.cpp) to library project which main project depends, gtest don't work.
但是,当我将这些gtest代码(.cpp)移至主项目所依赖的库项目时,gtest无法正常工作。 I can't put breakpoint as if there is no code.
我不能像没有代码一样放置断点。 (BreakPoint point looks like white circle not red circle).
(BreakPoint点看起来像白色圆圈而不是红色圆圈)。 I guess compiler optimizer omit these static variables code in cpp because these variables are references nowhere.
我猜编译器优化器会在cpp中省略这些静态变量代码,因为这些变量无处引用。 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?
或任何专业知识?
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
.lib中的C ++静态变量未初始化, 强制Visual Studio链接lib文件中的所有符号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.