I have a problem with starting using Gtest and Gmock on Windows10. I normally work on Linux but wanted to switch to Windows and encountered a problem.
I managed to build the Gmock and Gtest according to the documentation (with Cmake and Visual Studio). I have the gmock.lib and gtest.lib files in apropriate directories. But when I want to link them to my test program I can see dozens of errors of type "undefined reference".
The command I use is:
g++ "-LC:\\Users\\jacek\\cpp\\googletest\\googlemock\\Debug" "-LC:\\Users\\jacek\\cpp\\googletest\\googlemock\\gtest\\Debug" -o HelloWorld "src\\counter.o" "src\\counter_test.o" -lgmock -lgtest
The errors are for example:
C:\Users\jacek\workspace\HelloWorld\Debug/../src/counter_test.cpp:14: undefined reference to testing::Message::Message()' C:\Users\jacek\workspace\HelloWorld\Debug/../src/counter_test.cpp:14: undefined reference to testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
I tried searching on this and found that maybe I should build shared libraries. I rebuilt the gmock and gtest with appropriate option, now I have also dll files, but I receive still the same errors.
What am I doing wrong here?
Can it be an issue that the libraries on linux are named differently than on windows? (libgmock.a vs gmock.lib) Should I change something in the command to g++ due to that?
The paths I pasted are good, the files are there (otherwise the error would be different).
What am I missing here?
Ok, I solved the problem. It turned out that I cannot compile libraries with Visual Studio and then use it with G++. I had to switch to a different approach and this video was very helpful: https://www.youtube.com/watch?v=y9sGAF1k63o&list=PL0SUKxlBaq1COi52nuq2lPf6AbMRrn2LI&index=7
The video teaches how to use gtest with Eclipse but not using library but fused cpp and h files from gtest script. It works fine. The only problem I had is that I installed python 3.5 version and it is not backwards compatible in some cases with python 2.7 used in the 'fuse' script, but I managed to quickly correct these few cases and make it work.