加速测试链接 [英] Boost test linking
问题描述
我想用升压试验
在我的项目。
我用cmake的在我的项目,所以我写了一个简单的 CMakeList.txt
用于包装的:
I use cmake in my project so I wrote a simple CMakeList.txt
for wrapping it:
find_package (Boost COMPONENTS unit_test_framework REQUIRED)
file(GLOB_RECURSE UnitTests_sources tests/*.cpp)
add_executable(UnitTests
${UnitTests_sources}
)
enable_testing()
ADD_TEST (UnitTests UnitTests)
于是,CMake的工作在这里很好。在编译期间麻烦就变成了:
So, cmake works fine here. The trouble becomes during compiling:
链接CXX可执行../../斌/单元测试
Linking CXX executable ../../bin/UnitTests
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.1 /../../../../的lib / crt1.o:在
功能 _start':(+的.text 0x20的):未定义引用
主要
collect2:劳工处返回1退出状态
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.1/../../../../lib/crt1.o: In
function _start': (.text+0x20): undefined reference to
main'
collect2: ld returned 1 exit status
下面是唯一的文件的测试文件夹( LogManagerTest.cpp
)
Here is the only file in tests folder (LogManagerTest.cpp
):
#include "Utils/LogManager.hpp"
#include <boost/test/unit_test.hpp>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE LogManager
BOOST_AUTO_TEST_CASE(LogManagerCase)
{
BOOST_REQUIRE(true);
/*LogManager manager;
manager.Initialize();
manager.Deinitialize();*/
}
什么是错在这里?
What's wrong here?
推荐答案
添加
ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)
您的CMakeLists.txt所以它会自动生成一个main()为您服务。
此外,
to your CMakeLists.txt so it will automatically generate a main() for you. Also,
#define BOOST_TEST_MODULE xxx
您有unit_test.hpp之前,必须先定义。
must be defined before you include unit_test.hpp.
您可以找到更多的信息和选项:
<一href=\"http://www.boost.org/doc/libs/1_47_0/libs/test/doc/html/utf/compilation.html\">http://www.boost.org/doc/libs/1_47_0/libs/test/doc/html/utf/compilation.html
You can find more information and options on: http://www.boost.org/doc/libs/1_47_0/libs/test/doc/html/utf/compilation.html
这篇关于加速测试链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!