简体   繁体   English

如何避免C ++编译器优化程序删除静态变量代码?

[英]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.

相关问题 如何避免在C ++中使用静态构造函数? - How to avoid using static constructor in c++? 如何提示Visual C ++编译器优化器不能执行if语句的特定分支? - How to hint to Visual C++ compiler optimizer that a specific branch of an if-statement is unlikely to be executed? 我怎么知道C ++编译器是否制作了线程安全的静态对象代码? - How can I know if C++ compiler make thread-safe static object code? 英特尔C ++优化器删除了masm代码 - Intel C++ optimizer removes masm code 如何防止 c++ 编译器优化变量 - How to prevent c++ compiler optimising variable C ++给编译器错误,以将(静态)const全局变量设置为另一个静态const变量 - C++ Give compiler error for setting a (static) const global variable to another static const variable 如何检查C ++编译器生成的代码? - How to check code generated by C++ compiler? 如何在不运行静态代码分析的情况下使用 Visual C++ 在我自己的代码中引起 SAL 编译器警告 - How to cause SAL compiler warnings in my own code using Visual C++ without running static code analysis 在C ++中禁止使用未使用的变量警告=>编译器错误或代码错误? - Suppress unused variable warning in C++ => Compiler bug or code bug? C++ 编译器中的 C 代码 - C code in C++ compiler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM