PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Problem linking when using Surface::Create

Hi guys,

I really like Pocket HAL/Frog :D and I'm working on a little project that implements a GUI. For this reason I like to use the Surface::Create method to create a surface from an existing memory location. But...

I can't use the Surface::Create(unsigned short *, unsigned, unsigned, unsigned) since the linker will bail with the following error:

Code:
unresolved external symbol
"public: static class PHAL::Surface * __cdecl PHAL::Surface::Create(unsigned short *,unsigned int,unsigned int,unsigned int)"
(?Create@Surface@PHAL@@SAPAV12@PAGIII@Z)


I even tried subclassing Surface and using the constructor (which is protected), but again a linking error, this time it can't find the constructor 8O .

When I run DumpBin on the pockethal_arm.lib I notice the method (and constructor) are there, but the mangled names are a little different:

Code:

vc++ wants ?Create@Surface@PHAL@@SAPAV12@PAGIII@Z) but,
lib has ?Create@Surface@PHAL@@SAPAV12@PA_GIII@Z


Notice the underscore. What I can tell from DumpBin is that the first parameter is defined as "unsigned __int16 *", but the linker is looking for "unsigned short *". Might it be that Pocket Hal has been compiled with a pre 2003 compiler that uses different namemangeling for __int16?

I really can't figure this out, and I would like to use the Create inside an existing memory location. Does any one experience similair problems?

I tried with VC++ .NET 2003, and .NET 2005 with no avail.

Or is it that I'm doing something completly wrong, which is weird since I can compile the samples so my setup is ok.

Thanks,
Robert
robostyle · 24 Sep 2007, 20:29 UTC — Replying to myself
Managed to find some time to research this a bit more. I installed Embedded Visual C++ 4. I made this piece of code to demonstrate (which has the same prototype as the one in the pocket HAL library):

Code:
#include <windows.h>

class surface
{
public:
static surface* create(unsigned __int16 *p, unsigned w, unsigned h, unsigned pitch);
};

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
unsigned __int16 pixels[320*80];

surface *s = surface::create(pixels, 160, 80, 320);

return 0;
}


When I compile this with eVC4 I get the following linker error:

Code:
main.obj : error LNK2019: unresolved external symbol
"public: static class surface * __cdecl surface::create(unsigned __int16 *,unsigned int,unsigned int,unsigned int)" (?create@surface@@SAPAV1@PA_GIII@Z)
referenced in function WinMain


When I compile it under VC++ 2005 I get:

Code:
main.obj : error LNK2019: unresolved external symbol
"public: static class surface * __cdecl surface::create(unsigned short *,unsigned int,unsigned int,unsigned int)" (?create@surface@@SAPAV1@PAGIII@Z)
referenced in function WinMain


So the problem is that the name is mangled different for the unsigned __int16 type which apparently is converted to unsigned short under VC++ 2005.

So I guess I'm a bit stuck here since the Pocket HAL libraries are compiled with the __int16 type.
That´s a nice one. I find it odd that it hasn´t shown up before. In fact, it would mean VS2005 isn´t backward compatible with EVC4. That surprises me a lot.

I should be able to look into it early next week.

Meanwhile, have you tried modifying the header to use unsigned __int16 instead of unsigned short? Sounds like it´s worth a try.
Kzinti wrote:In fact, it would mean VS2005 isn´t backward compatible with EVC4.


Neither does VS2003, which I tried when I couldn't get it going under VS2005.

Kzinti wrote:Meanwhile, have you tried modifying the header to use unsigned __int16 instead of unsigned short? Sounds like it´s worth a try.


Yeah, that was one of the first things I tried.

But the fact remains that the .lib has the wrong mangled name, and VC2005 seems to convert __int16 to short.

Thanks for the reply, If you come up with something I could try, or need more info let me know.
I reproduced this problem. Trying to find a solution.
Fixed for 1.0.2.
Kzinti wrote:Fixed for 1.0.2.


Thanks for this, I will try this next week since I'm unable to find any time this week.
Ok I did manage to find some time to do a quick test. For the ARM library this is fixed now, but the x86 version still suffers from this same problem, and I use this one for testing since debugging on a device is like ehhhh.. so sllloooowwww

Looking at the dates I see that only the ARM library was rebuild. So that figures (I guess) :o

Looking at the other libraries revealed they also suffer from the same problem, but these are less important since they're not supported by VS .NET 200x anyways.

Might this be the same issue?

Thanks for your time,
Robert
Yes. I only recompiled the ARM version. Oops.

Not sure I want to do another release for this. Send me your email and I will update you directly.