7

When building a test with QTestLib, I get an "undefined symbols" error for a qCompare function:

Undefined symbols for architecture x86_64:
  "__ZN5QTest8qCompareIimEEbRKT_RKT0_PKcS8_S8_i", referenced from:
      __ZN15MyTestClass22myTestFunctionEv in MyTestClass.o
jlstrecker
  • 4,953
  • 3
  • 46
  • 60

1 Answers1

8

You can decipher the mangled symbol by passing it through c++filt in a shell command:

echo __ZN5QTest8qCompareIimEEbRKT_RKT0_PKcS8_S8_i | c++filt

... which prints a C++ function signature like this:

bool QTest::qCompare<int, unsigned long>(int const&, unsigned long const&, char const*, char const*, char const*, int)

The two arguments to the QCOMPARE macro — i.e., the two template arguments to the qCompare function — must have exactly the same type. You get an error, for example, if one is an int and the other is a size_t.

jlstrecker
  • 4,953
  • 3
  • 46
  • 60
  • 3
    ...so the solution is to static_cast the types or, in case ofliterals, use the correct type by using "0ul" etc. – Frank Osterfeld Jan 07 '13 at 17:59
  • FYI: It seems that this is no longer an issue with more recent versions of Qt (on Ubuntu 18.04 the error is still seen whereas on Ubuntu 20.04 it is gone). – Raven Dec 01 '21 at 09:31