c++cmakegoogletest

WSL picking up windows path when using CMake


I installed googletest in WSL. I copied the gtest static libraries to /usr/lib. And then moved gtest and gmock folders to /usr/local/include/.

I wrote a simple program for gtest and it worked using the command :

g++ -o exec main.cpp -lgtest -lpthread

But when I try with CMake and make I get errors. What I noticed is that cmake is fetching the windows path.

CMakeLists.txt

cmake_minimum_required(VERSION 3.13)

find_package(GTest REQUIRED)
message("GTest_INCLUDE_DIRS = ${GTest_INCLUDE_DIRS}")

add_executable(my_executable main.cpp)

target_link_libraries(my_executable ${GTEST_LIBRARIES} pthread)

Fetching path from Windows in CMakeCache.txt

//The directory containing a CMake configuration file for GTest.
GTest_DIR:PATH=/mnt/c/msys64/mingw64/lib/cmake/GTest

Errors that I get :

/usr/bin/ld: /mnt/c/msys64/mingw64/bin/libgtest.dll:(.idata+0xc34): multiple definition of `__imp__ZTVNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE'; /mnt/c/msys64/mingw64/bin/libgtest.dll:(.idata+0xc34): first defined here
main.cpp:(.text+0x91): undefined reference to `testing::Message::Message()'
/usr/bin/ld: main.cpp:(.text+0xc0): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'

Solution

  • The Windows paths in WSL were interfering with GTest.

    I just disabled the Windows path and it started working fine.

    https://stackoverflow.com/a/51345880/8551671