Jump to content
  • Advertisement
Sign in to follow this  
likeafox

How use header file??

This topic is 4330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I'm making an MMORPG but I have a problem. I have a few files with code, but I get "unresolved externals" when I try compile. My files look something like this: // player.h void moveplayer(int, int, int, float); // player.cpp # include "player.h" void moveplayer(int p, int x, int y, float dir) { player

.x = x; player

.y = y; player

.dir = dir; return; } // mmorpg.cpp #include "player.h" main (){ ... moveplayer(0, 10, 10, 3*pi); ... } For some reason it says moveplayer() is a unresolved external! How am I doing it wrong to include this thing? Is there a good page on the internet that explains good project-file structure? [Edited by - likeafox on January 31, 2007 10:20:22 PM]

Share this post


Link to post
Share on other sites
Advertisement
you might wanna try using...

#ifndef _player_h_included
#define _player_h_included

//header info

#endif


...since your problem may be a repeated definition. This solved a past problem I had with compiling C++ headers, and may be a solution for you as well.

Share this post


Link to post
Share on other sites
Quote:
Original post by likeafox
Is there a good page on the internet that explains good project-file structure?

Yep!

-jouley

Share this post


Link to post
Share on other sites
The linker cannot find the definition of moveplayer -- that's what "unresolved external" means. It doesn't exist. Are you sure player.cpp is being compiled and linked?

What tools (VC++, Dev-C++, etc?) are you using, and what does the full, real code look like?

Share this post


Link to post
Share on other sites
I'm using MSVCpp6

How do I make sure my player.cpp is being compiled and linked? It's in the project list on the side bar...

Share this post


Link to post
Share on other sites
Quote:
Original post by likeafox
How do I make sure my player.cpp is being compiled and linked?

When you build your project, does the build output say anything about player.cpp?

Share this post


Link to post
Share on other sites
Here's how it compiles

Deleting intermediate files and output files for project 'mmorpg - Win32 Debug'.
--------------------Configuration: mmorpg - Win32 Debug--------------------
Compiling...
mmorpg.cpp
player.cpp
messages.cpp
Generating Code...
Linking...
mmorpg.obj : error LNK2001: unresolved external symbol "void __cdecl moveplayer(int,int,int,float)" (?moveplayer@@YAXPAD_G@Z)
mmorpg.obj : error LNK2001: unresolved external symbol "int __cdecl attack(int,int,float)" (?attack@@YA_GPBD@Z)
mmorpg.obj : error LNK2001: unresolved external symbol "int __cdecl killplayer(int,int,int)" (?killplayer@@YAHPADHHH@Z)
Debug/mmorpg.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

mmorpg.exe - 4 error(s), 0 warning(s)

And the moveplayer function is in the player.h and player.cpp just like I showed before. And the player.h is included in the mmorpg.cpp and that's the only place I used the moveplayer()


edit: ALSO when I say #include "player.cpp" instead of "player.h" in my mmorpg.cpp, it compiles properly... but doesn't that defet the whole purpose of a header file??

Share this post


Link to post
Share on other sites
Quote:
Original post by likeafox
Hi I'm making an MMORPG


No, you aren't. Sorry.

Quote:
I'm using MSVCpp6


Please don't. It is many, MANY years out of date and the provided compiler does not conform to the current C++ standard.

Plus, it can be replaced *free* from Microsoft with more recent versions (I never can recall the details because I don't use their compilers or IDEs) if you want to stick with them; or with several other third-party options which are also free and certainly much better than VC++6.

Quote:
Is there a good page on the internet that explains good project-file structure?


Yes.

Share this post


Link to post
Share on other sites
Quote:

edit: ALSO when I say #include "player.cpp" instead of "player.h" in my mmorpg.cpp, it compiles properly... but doesn't that defet the whole purpose of a header file??

Yes, and its also completely wrong and will cause more problems in the future. The fact that it works suggests some things about how your code is organized; the articles people have linked to address some of those issues.

Once again, can you show us the exactly verbatim copy-and-paste contents of each file?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!