# FindGTest on windows with debug build

**URL:** <https://discourse.cmake.org/t/findgtest-on-windows-with-debug-build/239>\
**Category:** Code\
**Created:** [November 21, 2019, 7:27pm UTC](https://discourse.cmake.org/t/findgtest-on-windows-with-debug-build/239 "2019-11-21T19:27:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![smallzzy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/smallzzy/32/184_2.png) [@smallzzy](https://discourse.cmake.org/u/smallzzy)\
**Post date:** [November 21, 2019, 7:27pm UTC](https://discourse.cmake.org/t/findgtest-on-windows-with-debug-build/239/1 "2019-11-21T19:27:35Z")

</div>

I have built the googletest lib on windows with debug mode.  
It will generate gtestd.lib and gtest\_maind.lib.  
But find\_package(GTest) will fail to find them because of the suffix “d”.

I think the problem lies in the FindGTest.cmake:L205.

> FIND\_PACKAGE\_HANDLE\_STANDARD\_ARGS(GTest DEFAULT\_MSG GTEST\_LIBRARY TEST\_INCLUDE\_DIR GTEST\_MAIN\_LIBRARY)

It only looks for the non-d version of the lib despite GTEST\_LIBARAY\_DEBUG and GTEST\_MAIN\_LIBRARY\_DEBUG being set.

Am I correct? Otherwise, I would like to know how to build gtest on Windows and use it in visual studio.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [November 22, 2019, 12:38pm UTC](https://discourse.cmake.org/t/findgtest-on-windows-with-debug-build/239/2 "2019-11-22T12:38:35Z")

</div>

The `FindGTest` module will need to be updated to find the debug library variants. It appears as though `FindXercesC.cmake` does the proper logic that could be used as a template to get `FindGTest.cmake` to do the right thing here. Feel free to submit a merge request or an issue to get it fixed in CMake itself.

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [November 22, 2019, 11:43pm UTC](https://discourse.cmake.org/t/findgtest-on-windows-with-debug-build/239/3 "2019-11-22T23:43:15Z")

</div>

I’ve found that absorbing gtest directly into your build is a more robust and easier to use approach. It gets built with the same flags and settings as the rest of your project, which inherently takes care of most of the issues like the one you are facing. I recommend you take a look at the [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) module, the documentation for which even has examples for gtest.
