Unresolved externals!
Hi folks.
I have a function which I can call from one cpp-file, but if I call it from another cpp-file the linker gives me this very annoying unresolved externals error. If anyone have a clue of what could be the cause of this error I would appreciate it very much!
You need to write a header file that corresponds with the .cpp file with the functions you need to call from the other .cpp file. For example, if you had a .cpp file called graphics.cpp, then you would write a header file called graphics.h. Let''s say you have a function in graphics.cpp like this:
Then you would put the prototype for the function in graphics.h. If you wanted to call the function in graphics.cpp from another source file, like main.cpp, you would have to #include "graphics.h" in main.cpp. That should work. Also, if you want to access global variables from another .cpp file, you just write an extern in its header file. For instance:
Hope that answered your question.
Alex
void DrawStuff(){ // do stuff}
Then you would put the prototype for the function in graphics.h. If you wanted to call the function in graphics.cpp from another source file, like main.cpp, you would have to #include "graphics.h" in main.cpp. That should work. Also, if you want to access global variables from another .cpp file, you just write an extern in its header file. For instance:
extern int gVariable;
Hope that answered your question.
Alex
Alexbigshot@austin.rr.comFoolish man give wife grand piano. Wise man give wife upright organ.
It could also be that you are forgetting to link a libary (.lib) file you need so check that aswell
Thanks guys, but unfortunately this didn''t solve my problem. I have included a header file with the prototype, and since it works from at least one file it can''t be a missing library. (But correct me if I''m wrong on this one). Other ideas anyone?
What error are you getting specifically?
Alexbigshot@austin.rr.comFoolish man give wife grand piano. Wise man give wife upright organ.
Here''s the error:
error LNK2001: unresolved external symbol "void __cdecl tex (char *,int,int,unsigned long,struct IDirectDrawSurface7 *,struct HFONT__ *)" (?text@@YAXPADHHKPAUIDirectDrawSurface7@@PAUHFONT__@@@Z)
Hmm, looking at it more closely it seems like there''s those last two arguments there''s something fishy with.
But why???? The compiler doesn''t complain on anything, why does the linker?
error LNK2001: unresolved external symbol "void __cdecl tex (char *,int,int,unsigned long,struct IDirectDrawSurface7 *,struct HFONT__ *)" (?text@@YAXPADHHKPAUIDirectDrawSurface7@@PAUHFONT__@@@Z)
Hmm, looking at it more closely it seems like there''s those last two arguments there''s something fishy with.
But why???? The compiler doesn''t complain on anything, why does the linker?
Are you sure you are including the appropriate DirectX header files?
Because the linker is complaining it can''t find the DirectDraw Surface structure.
Regards,
Nekosion
Because the linker is complaining it can''t find the DirectDraw Surface structure.
Regards,
Nekosion
Regards,Nekosion
Oh yeah, and the windows header file as well.
This is because the compiler references the structures, and the linker has to actually "find" the structures and put them into the file while linking, it can''t do that if they are not defined. Hence you have to include the windows.h and ddraw.h files.
Regards,
Nekosion
This is because the compiler references the structures, and the linker has to actually "find" the structures and put them into the file while linking, it can''t do that if they are not defined. Hence you have to include the windows.h and ddraw.h files.
Regards,
Nekosion
Regards,Nekosion
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement