vc2005 link errors and warnings

Started by
1 comment, last by joanusdmentia 18 years ago
I have a class MetaScript with the following member function: GetClassInfo which takes a const char* now when i compile it seems to be spitting out a lot of __w64 warnings (ie cast warnings). It looks as though its trying to do a 64bit build? here is the link error: Entity.obj : error LNK2019: unresolved external symbol "public: struct ClassInfo const * __thiscall MetaScript::GetClassInfoW(char const *)" (?GetClassInfoW@MetaScript@@QAEPBUClassInfo@@PBD@Z) referenced in function "public: virtual bool __thiscall ListParser<class Entity *>::Read(struct MetadataTypeInfo const &,void *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,class MetaScript *)const " (?Read@?$ListParser@PAVEntity@@@@UBE_NABUMetadataTypeInfo@@PAXAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVMetaScript@@@Z) E:\BlackCarbon\Project\QuickGame\Source\Debug\QuickGame.exe : fatal error LNK1120: 1 unresolved externals edit: i should have posted this in the beginner section probably
Advertisement
This is one of the many reasons why #define's are evil. If you take a look at MSDN you'll see that GetClassInfo is infact part of the Win32 API, and like much of the API it uses define's to hide whether or not it's the unicode version of the function. In one of the windows include files there'll be something along the lines of
#ifdef _UNICODE_#define GetClassInfo GetClassInfoW#else#define GetClassInfo GetClassInfoA#undef

In your header file all is well because you haven't included <windows.h> yet, but in your source file you're including <windows.h>, thus every time GetClassInfo appears it gets replaced by one of the above....in particular the definition of that function in your class. If you really need <windows.h> you'll need to #undef GetClassInfo after you include <windows.h>.

If you think this problem could crop up a lot (eg. you regularly include <windows.h> in source files that call MetaScript::GetClassInfo) then you can either have a wrapper header for windows.h that #undef's any problem names (those damned min/max macros come to mind), or just use a different name.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Just looked at this again and realized I got it backwards. You're including <windows.h> in a .cpp file somewhere else that later includes your MetaScript class, thus the instances of GetClassInfo in the header get messed up and the source file is calling MetaScript::GetClassInfoW (instead of MetaScript::GetClassInfo). It doesn't complain at compile time (only link time) because <windows.h> is being included before the header containing the MetaScript class.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

This topic is closed to new replies.

Advertisement