ARTICLE AD BOX
I encountered this error when trying to compile a Gtest application using MinGW on Windows:
[build] D:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-ucrt_exit_wrappers.o):ucrt_exit_wrappers.c:(.rdata$.refptr.__imp__Exit[.refptr.__imp__Exit]+0x0): undefined reference to `__imp__Exit' [build] D:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-ucrt_exit_wrappers.o):ucrt_exit_wrappers.c:(.rdata$.refptr.__imp_quick_exit[.refptr.__imp_quick_exit]+0x0): undefined reference to `__imp_quick_exit'The code is very simple and is just used to test whether the compilation environment is set up successfully.
#include <gtest/gtest.h> TEST(ApplicationTest, DefaultConstruct) { int value = 1 + 1; EXPECT_EQ(value, 2); }and a CMakeLists.txt file placed in the test directory:
cmake_minimum_required(VERSION 3.14) project(entt_demo_tests) include(FetchContent) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.17.0 ) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) enable_testing() file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS *.cpp *.hpp) add_executable(${PROJECT_NAME} ${TEST_SOURCES}) target_link_libraries(${PROJECT_NAME} PRIVATE GTest::gtest GTest::gtest_main ) add_test( NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME} )This is the compiler I use:
> g++ --version g++.exe (x86_64-win32-seh-rev0, Built by MinGW-Builds project) 14.2.0 Copyright (C) 2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.