无法在Debug / X64中在Visual Studio中调试googletests

时间:2019-06-13 20:15:03

标签: cmake googletest visual-studio-2019

我无法在Debug模式下在Visual Studio2019中使用googletest运行测试。 实际上,我在不同的计算机上有不同的症状,因此我尝试构建一个非常简单的基本示例,希望该示例可以很好地说明我的问题,并且可以在此处找到:

https://github.com/Willyam42/mpb

基本上在发布模式下,它似乎可以正常工作。 在调试模式下,测试在VisualStudio2019测试窗口中不可见,我在输出窗口中得到以下消息:

[13/06/2019 20:47:17 Informational] ------ Discover test started ------
[13/06/2019 20:47:17 Warning] Test run will use DLL(s) built for framework Framework45. Following DLL(s) will not be part of run: 
mpblib.lib,testrun.exe are built for Framework None and Platform X64.
 Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.
[13/06/2019 20:47:19 Warning] Could not locate debug symbols for 'C:\Users\guill\build\mpblib\test\Debug\testrun.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[13/06/2019 20:47:19 Informational] Test Adapter for Google Test: Test discovery starting...
[13/06/2019 20:47:19 Informational] Test discovery completed, overall duration: 00:00:00.0607728
[13/06/2019 20:47:19 Warning] No test is available in C:\Users\guill\build\mpblib\src\Debug\mpblib.lib C:\Users\guill\build\mpblib\test\Debug\testrun.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

我尝试了Microsoft链接,它似乎没有任何用处。 我不明白为什么视觉效果“无法找到调试符号”,因为我是在调试模式下构建的。

我尝试朝这个方向看: https://social.msdn.microsoft.com/Forums/vstudio/en-US/8a4518be-d0ae-4c4a-9838-9251d346c3a4/test-run-will-use-dlls-built-for-framework-framework45-and-platform-x86

不确定是视觉工作室,cmake还是googletest问题。

这是用于构建测试(如果相关)的CMakeLists.txt。

file(
    GLOB_RECURSE _source_list 
    LIST_DIRECTORIES false
    "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp*"
    "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp"
)

set(Boost_USE_STATIC_LIBS OFF) 
set(Boost_USE_MULTITHREADED ON)  
set(Boost_USE_STATIC_RUNTIME OFF)
find_package (Boost COMPONENTS date_time REQUIRED)

message("CMAKE_SOURCE_DIR : ${CMAKE_SOURCE_DIR}")


include_directories (${CMAKE_SOURCE_DIR}/mpblib/src
                     ${Boost_INCLUDE_DIRS}
                     )               


find_package(GTest REQUIRED)
find_package( Threads REQUIRED )
include(GoogleTest)

link_directories(${Boost_LIBRARY_DIRS})

include_directories(${GTEST_INCLUDE_DIRS})

add_executable (testrun ${_source_list})
target_link_libraries (testrun                       
  ${Boost_DATE_TIME_LIBRARY}
  ${GTEST_LIBRARIES}
  ${GTEST_MAIN_LIBRARIES}
  Threads::Threads
  mpblib
  )

gtest_discover_tests(testrun TEST_PREFIX new:)

foreach(_source IN ITEMS ${_source_list})
    get_filename_component(_source_path "${_source}" PATH)
    file(RELATIVE_PATH _source_path_rel "${CMAKE_CURRENT_SOURCE_DIR}" "${_source_path}")
    string(REPLACE "/" "\\" _group_path "${_source_path_rel}")
    source_group("${_group_path}" FILES "${_source}")
endforeach()

任何帮助将不胜感激!

0 个答案:

没有答案