Link error (LNK1120) in CPPUnit tests

hellhound_01 104 Jan 12, 2012 at 16:09


after Migration of our GCC compatible sources to MSVC I’ve some trouble to get the CPPUnit tests
runable. If those tests tries to access hidden members (private, protected) using preprocessor
macros like this on exported classes:

#define protected public
#include <brGraphics/brImage.h>
#undef protected

And tries to access a hidden method like this:

   unsigned int getNativePixelColor(const brColor& color);

I got the follwing error:

2>brImageTest.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ““__declspec(dllimport) public: unsigned int __thiscall binrev::brGraphics::brImage::getNativePixelColor(class binrev::brGraphics::brColor const &)” (__imp_?getNativePixelColor@brImage@brGraphics@binrev@@QAEIABVbrColor@23@@Z)” in Funktion ““public: void __thiscall binrev::test::brImageTest::testGetNativePixelColor(void)” (?testGetNativePixelColor@brImageTest@test@binrev@@QAEXXZ)”.

fatal error LNK1120: 1 nicht aufgelöste externe Verweise.

I tried to define the related methods public, in that case everything is running fine.
Any suggestions how I could solve this issue without making those methods public?

Best regards

2 Replies

Please log in or register to post a reply.

_oisyn 101 Jan 12, 2012 at 16:58

I don’t think you can, other than leaving the access specifiers be and befriending your unit test suite with the appropriate classes.
Unfortunately, MSVC++ mangles the access specifiers in the symbol names, which explains the linker errors.

hellhound_01 104 Jan 12, 2012 at 19:00

Thanks Oisyn for your explanation. I’ve to think about my access specifiers.
I now why I don’t like the MSVC, damn extras …