Posts Tagged ‘ googletest ’

gtest + CMake + Visual Studio

I should have posted this sooner, but all kinds of things got in the way and… Okay, that was just some lame excuse, it is because my laziness that this site has been left unattended.

I suddenly felt the urge of writing this post because the other day I saw my friend Dat was trying to get gtest to work with Visual Studio but ended up getting cryptic messages from linking errors. This has happened to me before, and I have investigated this issue.

In fact, using gtest library with CMake is fairly easy and straightforward. All you need to do is to find the corresponding library and the include path, and then link the gtest library against the executable. This works without a problem in Linux. However, it becomes a bit tricky when used in Windows (as expected?).

The main issue is the Runtime Library setting in Visual Studio:

By default, it tries to load DLL, but I was feeding it LIB file. No wonder it complains. Suppose I am building in debug mode, I need to specify gtestd.lib to be my target library and select “Multi-threaded Debug (/MTd)” as the runtime library, whereas in release mode gtest.lib needs to be specified and “Multi-threaded (/MT)” should be selected.

So, is there any workarounds to avoid this manual hassle? Sure, simply do

SET(CMAKE_CXX_FLAGS_DEBUG "/MTd")

in the CMakeLists.txt, and it will be set automatically (somehow I was under the impression that I have tested this before and it was not working, but it did work just now).

Of course, you can specifically indicate that you want a DLL to be built in gtest. Yet so far I haven’t found a way to utilize the DLL (such that it can work with /MD or /MDd), I would have to defer this problem to some C++ gurus, i.e. George Toderici (if Google Alert ever alerts him about the existence of this post), to answer.

A couple of good/exciting news

Out of no where (at least for me), Blizzard announced Diablo 3, the long waited successor of the famous Diablo series. Of course, I would assume (at least) another year and half before it going into beta, taking into consideration that even StarCraft 2 does not have a beta yet. Blizzard is “notorious” of postponing delivery of the final products, as they always claim that they want to take as much time as needed to achieve certain level of perfection.

Another piece of exciting news is that a bunch of Google developers have initiated the Google C++ Testing Framework project. I am not a fanatic fan of unit testing like Dat, but I do appreciate the merits of test driven development (TDD). Previously there was (there still is now) CppUnit, but it was not so straightforward to configure to work with Visual Studio. This can be attested by both Dat and me. Judging from the README and samples of googletest, everything should be as easy as in Ruby and Java. I will try it out when I finish the work at hand. The very first thing I need to do, however, is to figure out how to write the CMakeLists.txt to incorporate the test framework in a new project.

Last but not the least, I think I found a hole in AT&T’s iPhone 3G upgrade plan. According its policy, ineligible AT&T users need to pay $399/$499 for the 8G/16G model, but users who are currently on an iPhone plan are by default eligible for the upgrade price ($199/$299). Thus, before July 11th, which is the date when iPhone 3G goes on sale, if you can somehow get a hold of the first generation of iPhone, you can insert a new SIM card and activate it with your current number, which will upgrade your plan to an iPhone plan. Unless you have to show that you have an original iPhone when purchasing the new 3G model, you are qualified to upgrade just as other iPhone users.

I am not sure how AT&T countermeasure this kind of “hand-me-down” abuse. Maybe they do, but another ironic fact is that even if you start another new plan and pay for the early cancellation fee ($175), that will be only 175 + 199 = 374 for you to get an iPhone without a plan. Adding one month service fee, it is still less than $599 (price to get an iPhone 3G without signing a 2-year contract). What the heck were you thinking, AT&T?