I just cloned https://github.com/google/googletest, created a new visual studio (2022 professional) DLL project and copied directories https://github.com/google/googletest/tree/main/googletest/include/ and https://github.com/google/googletest/tree/main/googletest/src into the project folder and added $(ProjectDir);$(ProjectDir)include
to the project’s “Properties –> C++ –> Additional Include Directories” and then replaced all #include "gtest/
with #include "../include/gtest/
and all #include "src/
with #include "../src/
and built the project. Compilation went fine but linking did not as I had roughly 400 linking errors :
1>gtest-assertion-result.obj : error LNK2005: "public: __cdecl testing::AssertionResult::AssertionResult(class testing::AssertionResult const &)" (??0AssertionResult@testing@@QEAA@AEBV01@@Z) already defined in gtest-all.obj
1>gtest-assertion-result.obj : error LNK2005: "public: class testing::AssertionResult __cdecl testing::AssertionResult::operator!(void)const " (??7AssertionResult@testing@@QEBA?AV01@XZ) already defined in gtest-all.obj
1>gtest-assertion-result.obj : error LNK2005: "class testing::AssertionResult __cdecl testing::AssertionFailure(class testing::Message const &)" (?AssertionFailure@testing@@YA?AVAssertionResult@1@AEBVMessage@1@@Z) already defined in gtest-all.obj
1>gtest-assertion-result.obj : error LNK2005: "class testing::AssertionResult __cdecl testing::AssertionFailure(void)" (?AssertionFailure@testing@@YA?AVAssertionResult@1@XZ) already defined in gtest-all.obj
1>gtest-assertion-result.obj : error LNK2005: "class testing::AssertionResult __cdecl testing::AssertionSuccess(void)" (?AssertionSuccess@testing@@YA?AVAssertionResult@1@XZ) already defined in gtest-all.obj
1>gtest-assertion-result.obj : error LNK2005: "private: void __cdecl testing::AssertionResult::swap(class testing::AssertionResult &)" (?swap@AssertionResult@testing@@AEAAXAEAV12@@Z) already defined in gtest-all.obj
1>gtest-death-test.obj : error LNK2005: "public: __cdecl testing::internal::DeathTest::DeathTest(void)" (??0DeathTest@internal@testing@@QEAA@XZ) already defined in gtest-all.obj
1>gtest-death-test.obj : error LNK2005: "public: __cdecl testing::ExitedWithCode::ExitedWithCode(int)" (??0ExitedWithCode@testing@@QEAA@H@Z) already defined in gtest-all.obj
1>gtest-death-test.obj : error LNK2005: "public: bool __cdecl testing::ExitedWithCode::operator()(int)const " (??RExitedWithCode@testing@@QEBA_NH@Z) already defined in gtest-all.obj
1>gtest-death-test.obj : error LNK2005: "protected: virtual void __cdecl testing::internal::DeathTestImpl::Abort(enum testing::internal::DeathTest::AbortReason)" (?Abort@DeathTestImpl@internal@testing@@MEAAXW4AbortReason@DeathTest@23@@Z) already defined in gtest-all.obj
1>gtest-death-test.obj : error LNK2005: "public: virtual enum testing::internal::DeathTest::TestRole __cdecl testing::internal::WindowsDeathTest::AssumeRole(void)" (?AssumeRole@WindowsDeathTest@internal@testing@@UEAA?AW4TestRole@DeathTest@23@XZ) already defined in gtest-all.obj
1>gtest-death-test.obj : error LNK2005: "public: static bool __cdecl testing::internal::DeathTest::Create(char const *,class testing::Matcher<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &>,char const *,int,class testing::internal::DeathTest * *)" (?Create@DeathTest@internal@testing@@SA_NPEBDV?$Matcher@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@3@0HPEAPEAV123@@Z) already defined in gtest-all.obj
1>gtest-death-test.obj : error LNK2005: "public: virtual bool __cdecl testing::internal::DefaultDeathTestFactory::Create(char const *,class testing::Matcher<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &>,char const *,int,class testing::internal::DeathTest * *)" (?Create@DefaultDeathTestFactory@internal@testing@@UEAA_NPEBDV?$Matcher@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@3@0HPEAPEAVDeathTest@23@@Z) already defined in gtest-all.obj
1>gtest-death-test.obj : error LNK2005: "bool __cdecl testing::internal::ExitedUnsuccessfully(int)" (?ExitedUnsuccessfully@internal@testing@@YA_NH@Z) already defined in gtest-all.obj
1>gtest-death-test.obj : error LNK2005: "protected: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl testing::internal::DeathTestImpl::GetErrorLogs(void)" (?GetErrorLogs@DeathTestImpl@internal@testing@@MEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) already defined in gtest-all.obj
1>gtest-death-test.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl testing::internal::GetLastErrnoDescription(void)" (?GetLastErrnoDescription@internal@testing@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) already defined in gtest-all.obj
1>gtest-death-test.obj : error LNK2005: "bool __cdecl testing::internal::InDeathTestChild(void)" (?InDeathTestChild@internal@testing@@YA_NXZ) already defined in gtest-all.obj
...
1>gtest.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > testing::FLAGS_gtest_stream_result_to" (?FLAGS_gtest_stream_result_to@testing@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in gtest-all.obj
1>gtest.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > testing::FLAGS_gtest_flagfile" (?FLAGS_gtest_flagfile@testing@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in gtest-all.obj
1>gtest.obj : error LNK2005: "void const * const testing::internal::kTestTypeIdInGoogleTest" (?kTestTypeIdInGoogleTest@internal@testing@@3QEBXEB) already defined in gtest-all.obj
1>C:Googletestx64DebugGoogletest.dll : fatal error LNK1169: one or more multiply defined symbols found
What am I doing wrong ?