I get the following error when attempting to build a CMake project which uses GTest. Any ideas what I'm doing wrong? (Please see the minimal example I provide in the link)
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found GTest: C:/Users/runneradmin/miniconda3/envs/dev-env/Library/lib/cmake/GTest/GTestConfig.cmake (found suitable version "1.14.0", minimum required is "1.14")
-- Configuring done (18.3s)
-- Generating done (0.0s)
-- Build files have been written to: D:/a/gtest-example/build
[1/2] Building CXX object CMakeFiles/MyTests.dir/MyTest.cpp.obj
[2/2] Linking CXX executable MyTests.exe
FAILED: MyTests.exe
C:\Windows\system32\cmd.exe /C "cd . && C:\mingw64\bin\c++.exe CMakeFiles/MyTests.dir/MyTest.cpp.obj -o MyTests.exe -Wl,--out-implib,libMyTests.dll.a -Wl,--major-image-version,0,--minor-image-version,0 C:/Users/runneradmin/miniconda3/envs/dev-env/Library/lib/gtest_main.lib C:/Users/runneradmin/miniconda3/envs/dev-env/Library/lib/gtest.lib -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text+0x4b): undefined reference to `testing::Message::Message()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text+0x75): undefined reference to `testing::internal::GetBoolAssertionFailureMessage[abi:cxx[11](https://github.com/robertapplin/gtest-example/actions/runs/9146881036/job/25147633224?pr=1#step:4:12)](testing::AssertionResult const&, char const*, char const*, char const*)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/[12](https://github.com/robertapplin/gtest-example/actions/runs/9146881036/job/25147633224?pr=1#step:4:13).2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text+0xa7): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text+0xb7): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text+0xc3): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text+0x107): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text+0x28f): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text$_ZN7testing8internal16SuiteApiResolverI6MyTestE19GetSetUpCaseOrSuiteEPKci[_ZN7testing8internal16SuiteApiResolverI6MyTestE19GetSetUpCaseOrSuiteEPKci]+0x6c): undefined reference to `testing::internal::IsTrue(bool)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text$_ZN7testing8internal16SuiteApiResolverI6MyTestE19GetSetUpCaseOrSuiteEPKci[_ZN7testing8internal16SuiteApiResolverI6MyTestE19GetSetUpCaseOrSuiteEPKci]+0x92): undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text$_ZN7testing8internal16SuiteApiResolverI6MyTestE19GetSetUpCaseOrSuiteEPKci[_ZN7testing8internal16SuiteApiResolverI6MyTestE19GetSetUpCaseOrSuiteEPKci]+0xfc): undefined reference to `testing::internal::GTestLog::~GTestLog()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text$_ZN7testing8internal16SuiteApiResolverI6MyTestE19GetSetUpCaseOrSuiteEPKci[_ZN7testing8internal16SuiteApiResolverI6MyTestE19GetSetUpCaseOrSuiteEPKci]+0x11e): undefined reference to `testing::internal::GTestLog::~GTestLog()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text$_ZN7testing8internal16SuiteApiResolverI6MyTestE22GetTearDownCaseOrSuiteEPKci[_ZN7testing8internal16SuiteApiResolverI6MyTestE22GetTearDownCaseOrSuiteEPKci]+0x6c): undefined reference to `testing::internal::IsTrue(bool)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text$_ZN7testing8internal16SuiteApiResolverI6MyTestE22GetTearDownCaseOrSuiteEPKci[_ZN7testing8internal16SuiteApiResolverI6MyTestE22GetTearDownCaseOrSuiteEPKci]+0x92): undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text$_ZN7testing8internal16SuiteApiResolverI6MyTestE22GetTearDownCaseOrSuiteEPKci[_ZN7testing8internal16SuiteApiResolverI6MyTestE22GetTearDownCaseOrSuiteEPKci]+0xfc): undefined reference to `testing::internal::GTestLog::~GTestLog()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text$_ZN7testing8internal16SuiteApiResolverI6MyTestE22GetTearDownCaseOrSuiteEPKci[_ZN7testing8internal16SuiteApiResolverI6MyTestE22GetTearDownCaseOrSuiteEPKci]+0x11e): undefined reference to `testing::internal::GTestLog::~GTestLog()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.rdata$_ZTV42MyTest_test_example_which_should_fail_Test[_ZTV42MyTest_test_example_which_should_fail_Test]+0x28): undefined reference to `testing::Test::TearDown()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text$_ZN6MyTestD2Ev[_ZN6MyTestD2Ev]+0x32): undefined reference to `testing::Test::~Test()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.rdata$_ZTV6MyTest[_ZTV6MyTest]+0x28): undefined reference to `testing::Test::TearDown()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyTests.dir/MyTest.cpp.obj:MyTest.cpp:(.text$_ZN6MyTestC2Ev[_ZN6MyTestC2Ev]+0x[14](https://github.com/robertapplin/gtest-example/actions/runs/9146881036/job/25147633224?pr=1#step:4:15)): undefined reference to `testing::Test::Test()'
Describe the issue
I get the following error when attempting to build a CMake project which uses GTest. Any ideas what I'm doing wrong? (Please see the minimal example I provide in the link)
Steps to reproduce the problem
See the minimal example in this repository https://github.com/robertapplin/gtest-example/pull/1
The pull request has the
undefined reference
errorWhat version of GoogleTest are you using?
1.14
What operating system and version are you using?
Windows-latest
What compiler and version are you using?
GNU 12.2.0
What build system are you using?
cmake version 3.29.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
Additional context
No response