我刚刚下载了cxxtest的4.4版,并将我的zip文件解压缩到这个路径:C:/cxxtest-4.4。 现在紧接着,在没有做任何额外步骤的情况下,我打开了CLion并尝试将CxxTest添加到我的项目中,如下所示:
set(CXXTEST_PYTHON_TESTGEN_EXECUTABLE C:/cxxtest-4.4/python/cxxtest/cxxtestgen.py)
find_package(CxxTest REQUIRED)
if(CXXTEST_FOUND)
set(SOURCE_FILES main.cpp Calculator.h TestCalculator.h Calculator.cpp TestCalculator.h)
add_executable(Calculator ${SOURCE_FILES})
endif()
如果我不能得到以下错误,我必须手动设置两个变量:
"C:\Program Files (x86)\JetBrains\CLion 2017.1\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Admin\CLionProjects\Calculator
CMake Error at C:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find CxxTest (missing: CXXTEST_PYTHON_TESTGEN_EXECUTABLE)
Call Stack (most recent call first):
C:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake- 3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake- 3.7/Modules/FindCxxTest.cmake:221 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:9 (find_package)
-- Configuring incomplete, errors occurred!
See also "C:/Users/Admin/CLionProjects/Calculator/cmake-build- debug/CMakeFiles/CMakeOutput.log".
现在一切看起来都很好,这是我的Cmake调试:
"C:\Program Files (x86)\JetBrains\CLion 2017.1\bin\cmake\bin\cmake.exe" - DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Admin\CLionProjects\Calculator
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Admin/CLionProjects/Calculator/cmake-build-debug
现在我尝试在头文件中使用cxxtest / TestSuite.h,它说它无法找到它。这让我抓狂,拜托,我需要你的帮助!
提前致谢!
修改:我设法将其链接起来,现在我可以找到头文件,将此行添加到CMake文件中:
include_directories(C:/cxxtest-4.4)
现在,当我构建时,我得到以下输出:
"C:\Program Files (x86)\JetBrains\CLion 2017.1\bin\cmake\bin\cmake.exe" -- build C:\Users\Admin\CLionProjects\Calculator\cmake-build-debug --target Calculator -- -j 8
[ 33%] Linking CXX executable Calculator.exe
CMakeFiles\Calculator.dir/objects.a(main.cpp.obj): In function ` ZN7CxxTest7trackerEv':
C:/cxxtest-4.4/cxxtest/TestTracker.h:130: undefined reference to `CxxTest::TestTracker::tracker()'
CMakeFiles\Calculator.dir/objects.a(main.cpp.obj): In function `ZN7CxxTest14numberToStringIlEEPcT_S1_S2_jj':
C:/cxxtest-4.4/cxxtest/ValueTraits.h:183: undefined reference to `CxxTest::digitToChar(unsigned int)'
CMakeFiles\Calculator.dir/objects.a(main.cpp.obj): In function `ZN7CxxTest14doAssertEqualsIiiEEvPKciS2_T_S2_T0_S2_':
C:/cxxtest-4.4/cxxtest/TestSuite.h:146: undefined reference to `CxxTest::doAbortTest()'
CMakeFiles\Calculator.dir/objects.a(main.cpp.obj):main.cpp:(.rdata$_ZTV14TestCalculator[__ZTV14TestCalculator]+0x14): undefined reference to `CxxTest::TestSuite::tearDown()'
CMakeFiles\Calculator.dir/objects.a(main.cpp.obj): In function `ZN14TestCalculatorD1Ev':
C:/Users/Admin/CLionProjects/Calculator/TestCalculator.h:8: undefined reference to `CxxTest::TestSuite::~TestSuite()'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\Calculator.dir\build.make:123: recipe for target 'Calculator.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Calculator.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Calculator.dir/rule' failed
mingw32-make.exe[3]: *** [Calculator.exe] Error 1
Makefile:117: recipe for target 'Calculator' failed
mingw32-make.exe[2]: *** [CMakeFiles/Calculator.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Calculator.dir/rule] Error 2
mingw32-make.exe: *** [Calculator] Error 2
答案 0 :(得分:1)
不确定这是否存在问题,请查看CxxTest的CMake文档CMake文档。
从您的示例CMakeLists文件中,您似乎已经完成了普通项目文件的剪切和过去。您不能包含main.cpp文件CxxTest会根据您的测试定义文件生成一个名为runner.cpp的文件。
因此,CMakeFiles.txt中的CxxTest部分应如下所示:
set(CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/deps/cxxtest/bin)
find_package(CxxTest REQUIRED)
if(CXXTEST_FOUND)
include_directories(${CXXTEST_INCLUDE_DIR})
enable_testing()
CXXTEST_ADD_TEST(tests
runner.cpp # THIS IS GENERATED BUT YOU NEED TO ADD IT HERE
c:/libraries/boost_1_63_0/boost/filesystem.hpp # THIS SHOULD NOT BE HARD CODED
${CMAKE_SOURCE_DIR}/source/string_tokenizer.cpp # YOUR PROJECT FILES THAT WILL BE USED FOR YOUR TEST
${CMAKE_CURRENT_SOURCE_DIR}/tests/test_stringtokenizer.h # YOUR TEST DESCRIPTION FILE
)
target_link_libraries(tests ${Boost_LIBRARIES}) # LINK BOOST / OTHER THIRD PARTY LIBS TO YOUR TEST
endif()
希望这有帮助。