2

I am currently trying to compile and link the CppUTest library with my project. I use CMake to create a Visual Studio 2013 Solution for the CppUTest-library and it builds.

However, when I link the created CppUTest.lib to my application I get an linker error telling me that it can not find multiple symbols like

??0Utest@@QAE@XZ)

or

?RunAllTests@CommandLineTestRunner@@SAHHPAPAD@Z

Now when I use dumpbin.exe on the lib and option /LINKERMEMBER I get a list of symbols in the library that includes the names

??0Utest@@QEAA@XZ

and

?RunAllTests@CommandLineTestRunner@@SAHHPEAPEAD@Z

So the names that actually exist are slightly different to the names that my projects expects and I have no idea what causes this problem. Is there any compile option that causes these changes or do I use a different compiler although I think it is the same?

Knitschi
  • 2,822
  • 3
  • 32
  • 51
  • 1
    Yes it suggests the library was built with slightly different options to your project. There's not much you can do except go through the options and try and work out what's different. – Jonathan Potter Dec 05 '15 at 10:15
  • Yes I did that, but I found nothing because I forgot to check the build configuration. But thank you anyway. – Knitschi Dec 05 '15 at 11:19

1 Answers1

5

Run the undname.exe utility from the Visual Studio Command Prompt. You get:

Undecoration of :- "??0Utest@@QAE@XZ"
is :- "public: __thiscall Utest::Utest(void)"

and

Undecoration of :- "??0Utest@@QEAA@XZ"
is :- "public: __cdecl Utest::Utest(void) __ptr64"

Clear enough that this is the default constructor of the Utest class. Note how the calling convention is different, __thiscall vs __cdecl. And how the library version has the __ptr64 attribute.

You see that attribute appear on 64-bit functions. x64 has only one calling convention and does not distinguish between __cdecl and __thiscall.

So it should start to get obvious, the linker wants the first one, the 32-bit version of the constructor. The 64-bit version you supplied can never work since you cannot mix 32-bit and 64-bit code. There should also be a loud warning about that, don't ignore such warnings.

Link to the 32-bit build of this library to fix your problem. Or build the x64 version of your program.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • You are right. I really forgot to set my test exe project to 64 bit. Most of the time I use CMake for creating projects, but in this case I just wanted to quickly try out the library by "manually" setting up a project in Visual Studio. Of course I forgot to change the default build configuration to x64. But thanks for the tip with the undname.exe utility. I did not now that tool yet. – Knitschi Dec 05 '15 at 11:12