I seem to have this same problem with Visual Studio 2008 SP1. I have
the static libraries of Google Mock 1.6 which I have compiled myself.
I have added both the library and headers to my project. The library
works fine until I try to define a mock method which has unsigned
short argument. Signed short works fine.
Compile output:
1>------ Build started: Project: GMockTest, Configuration: Debug Win32
------
1>Compiling...
1>main.cpp
1>Linking...
1>LINK : C:\Projects\MSVC\GMockTest\Debug\GMockTest.exe not found or
not built by the last incremental link; performing full link
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl
testing::internal::PrintTo(unsigned short,class
std::basic_ostream<char,struct std::char_traits<char> > *)" (?
PrintTo@internal@testing@@YAXGPAV?$basic_ostream@DU?
$char_traits@D@std@@@std@@@Z) referenced in function "public: static
void __cdecl testing::internal::UniversalPrinter<unsigned
short>::Print(unsigned short const &,class
std::basic_ostream<char,struct std::char_traits<char> > *)" (?Print@?
$UniversalPrinter@G@internal@testing@@SAXABGPAV?$basic_ostream@DU?
$char_traits@D@std@@@std@@@Z)
1>C:\Projects\MSVC\GMockTest\Debug\GMockTest.exe : fatal error
LNK1120: 1 unresolved externals
1>Build log was saved at "file://C:\Projects\MSVC\GMockTest\Debug
\BuildLog.htm"
1>GMockTest - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========
Here is small example code which causes the error:
#include <gmock/gmock.h>
class MockBug
{
public:
MOCK_METHOD1( foo, void( unsigned short bar ) ); // link error
};
int main(int argc, char *argv[])
{
MockBug bug;
return 0;
}
As a workaround, if I define following, before the class declaration,
the code compiles fine:
namespace testing {
namespace internal {
void PrintTo( unsigned short value, std::ostream* os ) { }
}
}
Best Regards,
Janne Hakonen
On Oct 28, 8:06 pm, Greg Miller <j...@google.com> wrote:
> Hi, Benoit.
>
> Have you added a
> gmock.vcproj<http://code.google.com/p/googlemock/source/browse/#svn%2Ftrunk%2Fmsvc...>reference
> to your project, or added gmock.lib explicitly to your linker
> settings?
> You can verify in your saved build log whether your project links in
> gmock.lib.
>
> HTH,
>
> Greg
>
> On Fri, Oct 28, 2011 at 5:54 AM, benoit vedrenne
> <benoit.vedre...@gmail.com>wrote:
This was indeed caused by the mismatching /Zc:wchar_t setting.
I failed to mention in the previous post that I had made that example
code as Qt Console Application project (with Qt Add-in 1.1.9).
Apparently the wchar_t setting is set to 'no' with that project
template, while Google Mock's project setting is set to 'yes' by
default.
When I recompiled Google Mock with the setting set to 'no' the linker
problem went away.
Thanks for help!
Janne