I have Microsoft Visual Studio 2013 Community Edition on Windows 7. I want to install gtest and gmock for C ++ in a new way than downloading headers and binaries or compiling myself.
I found Tools> Nuget Package Manager> Managing Nugets Packages for Solution I selected Online, then typed gtest. From the search results, I found Google Test, so I installed it for my current project. After installation, the code below compiles:
#include <iostream> #include <gtest\gtest.h> using namespace std; using namespace ::testing; int factorian(int n) { if (n == 0 || n == 1) return 1; else return n*factorian(n - 1); } TEST(factorianTest, simpleTest) { ASSERT_EQ(1, factorian(0)); ASSERT_EQ(1, factorian(1)); ASSERT_EQ(2, factorian(2)); } int main(int argc, char* argv[]) { InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
but he does not refer:
Error 1 error LNK2019: unresolved external symbol "bool __cdecl testing :: internal :: IsTrue (bool)" (? IsTrue @internal @testing @@ YA_N_N @Z) link in the function "public: void __thiscall testing :: internal :: scoped_ptr , class std :: allocator → :: reset (class std :: basic_string, class std :: allocator> *) "(? reset @? $ Scoped_ptr @V? $ Basic_string @DU? $ Char_traits @D @ stand @@ V ? $ Distributor @D @ 2 @@ stand @@@ internal @ testing @@ QAEXPAV? $ Basic_string @DU? $ Char_traits @D @std @@ V? $ Allocator @D @ 2 @@ std @@@ Z) c : \ Users \ Grzegorz \ documents \ visual studio 2013 \ Projects \ tmp \ tmp \ Source.obj tmp
So, I opened: Project Properties> Configuration Properties> Connector> Input and I added: gtest.lib but, unfortunately, I see:
Error 1 error LNK1104: cannot open file 'gtest.lib' c: \ Users \ Grzegorz \ documents \ visual studio 2013 \ Projects \ tmp \ tmp \ LINK tmp
when I add the full path to the file (I know I shouldn't) strange errors occur:
Error 2 of LNK2005 error: "public: __thiscall stand :: _ Container_base12 :: _ Container_base12 (are canceled)" (?? 0_Container_base12 @std @@ QAE @XZ), already defined in gtestd.lib (gtest-all.obj) c: \ Users \ Grzegorz \ documents \ visual studio
2013 \ Projects \ tmp \ tmp \ msvcprtd.lib (MSVCP120D.dll) tmp
so my question is how to compile and link Google tests in a C ++ project in Visual Studio 2013, but with Gtest installed by the NuGet package manager?