0

I am trying to build and run Google Test but encountered some issues. Any help greatly appreciated. I used CMake 2.8 (with UI) to create .sln and .vcproj files in the D:/MyBuild directory (as mentioned in the README file of google test). However, when I try to run the .sln file in the MyBuild directory, here is what I get (image): enter image description here

Also, here is a screenshot of the CMake which I used to create .sln files and .vcproj files in the D:/MyBuild directory.

enter image description here

ps. One thing I noticed is that README was giving instructions how to use non graphical version of CMake (e.g., 2.6) to install google test, however I used one with user interface - maybe I did something wrong there?

Fraser
  • 74,704
  • 20
  • 238
  • 215
pseudonym_127
  • 357
  • 7
  • 16

1 Answers1

3

You appear to have successfully built gtest's libs in Debug mode. However, by default the .sln doesn't contain any executables, so you can't actually run anything.

If you select the checkboxes in the CMake GUI for gtest_build_samples and/or gtest_build_tests and hit "Generate", then the Visual Studio solution should contain some executables.

From memory, these don't build cleanly, but I don't have MSVC 2010 to hand, so I can't be sure.

Fraser
  • 74,704
  • 20
  • 238
  • 215
  • Hi, thanks, indeed it had some effect now (many files have been created in the D:/MyBuild directory, I had checked both gtest_build_samples and gtest_build_tests). But now, when I tried to compile it, this is the result I get: "Build: 54 succeeded, 4 failed, 0 up-to-date, 2 skipped" -- which is good, but still I have 4 fails (errors). What shall I do further, do you have any hints? Thank you. – pseudonym_127 Apr 03 '13 at 22:21
  • You'd need to show the failure output, but it may be irrelevant. If you're building gtest to use it in one of your own projects, you probably already succeeded when you built just the libs. You just need to link to the gtest libs from your project and you're off and running. – Fraser Apr 03 '13 at 22:25
  • Ok, now I have only selected gtest_build_samples and less files have been generated but compilation was also successful - I hope I will be able now to move on... – pseudonym_127 Apr 03 '13 at 22:29
  • Hi Fraser, thanks - please see my new comment (above). yes, I hope I can move on now - I have never before done these linking etc. but hope to find info on it on the google test site. I'll come back here if I have some issues. Thanks!. – pseudonym_127 Apr 03 '13 at 22:32
  • OK - Good luck. One thing to watch for (refer to http://stackoverflow.com/a/4222169/424459 - item 5) is that you choose the correct C Runtime Library to link to. Going by your screenshot, you've *not* selected `gtest_force_shared_crt` checkbox which means you've build gtest with `/MT` flag (in Release) and `/MTd` flag (in Debug). I seem to recall that new VS projects default these to `/MD` and `MDd`. You should either change these in your new project, or rebuild gtest with the `gtest_force_shared_crt` checkbox selected. – Fraser Apr 03 '13 at 22:44
  • Hi Fraser, I looked at the link you provided, but it seems there is no "gtestd.lib" on my machine at all, and that is the error I got when I tried to compile a test program (according to the stack overflow instructions): "Error 1 error LNK1104: cannot open file 'gtestd.lib' c:\documents and settings\User\my documents\visual studio 2010\Projects\CowAsciiString_GTest\CowAsciiString_GTest\LINK" Can you help? – pseudonym_127 Apr 04 '13 at 10:09
  • Hi Fraser, btw I think I successfully managed to run the test program but I specified gtest.lib instead of gtestd.lib as in steps 6,7 of nonsensical101's answer on the link you provided. And now it works. Do you think I still did something wrong? (ps. I am building in Debug mode now). – pseudonym_127 Apr 04 '13 at 11:05
  • No - you're probably fine. Usually if you mix linking debug libs and release libs, you get linker errors. – Fraser Apr 04 '13 at 23:11
  • Yes, thanks, I also think should be ok as I am managing to successfully run the tests. – pseudonym_127 Apr 05 '13 at 12:43