Boost test linking

后端 未结 4 595
花落未央
花落未央 2020-12-23 22:45

I want to use Boost test in my project.

I use cmake in my project so I wrote a simple CMakeList.txt for wrapping it:



        
相关标签:
4条回答
  • 2020-12-23 23:14

    You need to compile with -lboost_unit_test_framework, boost generates the main for you if you use the BOOST_TEST_DYN_LINK so you need to tell the makefile to look for that main. Then you can compile using the following:

    #define BOOST_TEST_DYN_LINK
    #define BOOST_TEST_MODULE LogManager                                   
    BOOST_AUTO_TEST_CASE(LogManagerCase)                                   
    {                                                                      
        BOOST_REQUIRE(true);                                               
        /*LogManager manager;                                              
        manager.Initialize();                                              
        manager.Deinitialize();*/                                          
    }                                                                      
    BOOST_AUTO_TEST_SUITE_END()    
    
    0 讨论(0)
  • 2020-12-23 23:14

    Try moving

    #define BOOST_TEST_DYN_LINK
    #define BOOST_TEST_MAIN
    

    before your includes - it worked for me.

    0 讨论(0)
  • 2020-12-23 23:16

    Add

    ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK) 
    

    to your CMakeLists.txt so it will automatically generate a main() for you. Also,

    #define BOOST_TEST_MODULE xxx
    

    must be defined before you include unit_test.hpp.

    You can find more information and options on: http://www.boost.org/doc/libs/1_47_0/libs/test/doc/html/utf/compilation.html

    0 讨论(0)
  • 2020-12-23 23:17

    Once I made a stupid typo and also got this. And compiler was cheated.

    Just as "#define BOOTS_TEST_MODULE DUMMY". Yes, I like boots :)

    0 讨论(0)
提交回复
热议问题