zoukankan      html  css  js  c++  java
  • gtest note, mark

        

    Important note for Visual C++ users

    If you put your tests into a library and your main() function is in a different library or in your .exe file, those tests will not run. The reason is a bugin Visual C++. When you define your tests, Google Test creates certain static objects to register them. These objects are not referenced from elsewhere but their constructors are still supposed to run. When Visual C++ linker sees that nothing in the library is referenced from other places it throws the library out. You have to reference your library with tests from your main program to keep the linker from discarding it. Here is how to do it. Somewhere in your library code declare a function:

    __declspec(dllexport)intPullInMyLibrary(){return0;}

    If you put your tests in a static library (not DLL) then __declspec(dllexport) is not required. Now, in your main program, write a code that invokes that function:

    intPullInMyLibrary();
    staticint dummy =PullInMyLibrary();

    This will keep your tests referenced and will make them register themselves at startup.

    In addition, if you define your tests in a static library, add /OPT:NOREF to your main program linker options. If you use MSVC++ IDE, go to your .exe project properties/Configuration Properties/Linker/Optimization and set References setting to Keep Unreferenced Data (/OPT:NOREF). This will keep Visual C++ linker from discarding individual symbols generated by your tests from the final executable.

    There is one more pitfall, though. If you use Google Test as a static library (that's how it is defined in gtest.vcproj) your tests must also reside in a static library. If you have to have them in a DLL, you must change Google Test to build into a DLL as well. Otherwise your tests will not run correctly or will not run at all. The general conclusion here is: make your life easier - do not write your tests in libraries!

  • 相关阅读:
    圆圈中最后剩下的数字
    扑克牌的顺子
    n个骰子的点数
    翻转单词顺序和左旋转字符串
    和为s的两个数字 和为s的连续正数序列
    LINUX学习(1)
    社交分享(facebook分享、twitter分享、link分享、google分享)
    获得HttpWebResponse请求的详细错误内容
    获得用户IP、城市、国家等信息的api接口
    win10彻底关闭自动更新
  • 原文地址:https://www.cnblogs.com/winkyao/p/2851894.html
Copyright © 2011-2022 走看看