Archived

This topic is now archived and is closed to further replies.

explodingrabbit

Unresolved external symbol

Recommended Posts

Hi I''m having a problem. I have some code which includes another header file of my own, with a function prototype in it for a function called DrawText. If I attempt to call this function I get an unresolved external symbol error, but if I change the name of the function in the prototype and the actual source, it works fine. Why? I''m haven''t included any windows header files, and I''m using Visual C++, if that helps.

Share this post


Link to post
Share on other sites
Are you absolutely sure that you haven''t included windows.h or any other windows header in any of your files. I''m asking, because in windows DrawText is a macro, declared as either DrawTextW (in a UNICODE build) or DrawTextA (in an ASCII build), and if you include the header, but don''t link to the libraries, then you will get an unresolved external symbol for either DrawTextA or DrawTextW.

Please include the actual error message when asking questions like this.

Share this post


Link to post
Share on other sites
Thanks for your reply.

I realized that there was a macro in the windows header files, but I am sure I haven''t included any (it''s such a small piece of code). The error message was:

Button.obj : error LNK2001: unresolved external symbol "void __cdecl DrawText(unsigned short,unsigned short,float,unsigned short,unsigned char,char *,short)" (?DrawText@@YAXGGMGEPADF@Z)


Share this post


Link to post
Share on other sites
Ok, please don't think I'm nagging or being condescending here I just find it so strange that it would work if you change the name of the function, and the only thing I can come up with is a macro problem (I'm probably just short sighted though).

When you say that you haven't included any windows headers, do you mean just in that particular header/source pair where the DrawText function is declared/defined? Because even if you don't include the windows headers in the header and source file that contains your DrawText function, including a windows header in another source file (or header) that includes the DrawText header (in order to use the function), could mess it up, or if the DrawText c/cpp file includes another header which in turn includes windows.h and so on and so forth.

You could always call the function RenderText or something

Are you sure that you have the correct types in every call? So the compiler won't think there are multiple, overloaded DrawText functions. But of course, if that was the problem, it wouldn't work simply by changing the name of the function.

Edited by - Dactylos on July 31, 2001 6:56:07 AM

Share this post


Link to post
Share on other sites
Thanks again.

I''ve checked and double checked. Neither the header/source pair nor the code that actually uses the function includes any windows headers. In fact, I just tried using the function in some other code that does include the windows headers, and it works fine. This code, and the code that doesn''t work are the only two source files that use that header. Any more ideas?

Share this post


Link to post
Share on other sites
visual c++ automatically includes some files. you can find them in project->settings->link (you probably already know this) so maybe it''s alraedy included in one of the lib files
~~KaMiKaZ~~

Share this post


Link to post
Share on other sites
Those files aren''t ''included'' (not in the #include sense of the word), rather they are linked to.

If one of the default libs implemented the DrawText function (which I''m pretty sure they don''t), then no error would occurr. The unresolved external error says that the linker can''t find the code for a function.

Share this post


Link to post
Share on other sites
"void __cdecl DrawText(unsigned short,unsigned short,float,unsigned short,unsigned char,char *,short)" (?DrawText@@YAXGGMGEPADF@Z)"

Is this your DrawText procedure that is in the error message? If it's not, then you must have a link to another DrawText function somewhere either in your program, or the compiler settings. If this IS your function then check to make sure that the return type and parameters are exactly the same in all declarations, implementations, and calls you make to the procedure. If the parameter types don't match exactly you may get that error.

Regards,
Paulcoz.

Edited by - paulcoz on August 1, 2001 3:02:12 AM

Share this post


Link to post
Share on other sites
Yes, that is my function in the error message, and I''ve lost count of how many times I''ve checked the function parameters. I tried fiddling around with the code I''ve got, and I noticed that if I attempt to call the DrawText function from a static function it works, but if I call it from a external function it doesn''t. Does that give anyone any clues?

Share this post


Link to post
Share on other sites