Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / .h and .cpp

Author
Message
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 9th Dec 2008 19:56
This is driving me mad. I have a simple question which is hard to ask.

I have a Character class.(.h and .cpp)
I have a Buttons class.(.h and .cpp)

The Character class uses the Buttons class.
How should I include them in my project.
I can only get it to work if I have all headers in one file (.h)and all implementations in another(.cpp).

In main.cpp I have:
#include "DarkGDK.h"
#include "Character\\Character.h"
and Character.cpp is in the Character folder with it, this works if I have writen all my classes in Character.h and Character.cpp
but ive tried every combination to separate them but I always get errors.


1>Character.obj : error LNK2019: unresolved external symbol "public: bool __thiscall myButtons::buttonPressed(void)" (?buttonPressed@myButtons@@QAE_NXZ) referenced in function "public: void __thiscall myCharacter::update(void)" (?update@myCharacter@@QAEXXZ)
1>Debug\shooter.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\pc\My Documents\Visual Studio 2008\Projects\Project1\shooter\shooter\Debug\BuildLog.htm"
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Dec 2008 20:50
It's a little hard to diagnose your problem without any code, so I'll work it the other way with an example based on what you have posted.

Buttons.h


Buttons.cpp


Character.h


Character.cpp


main.cpp


I've avoided GDK here because it hasn't got anything to do with your problem and would probably get in the way of the example. This code will compile and link cleanly as a console application.

Now, what am I doing that you aren't, or what are you doing that I'm not?

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 9th Dec 2008 21:25
That is what I was looking for.
I was not using:
#ifndef
#define
#endif
do you need these?
Ive put them in but get same error message.

main.cpp

#include "DarkGDK.h"
#include "Character\\Character.h"

where should the files be held, in Character folder?
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 9th Dec 2008 21:28
The #define etc are used so a file is not included more than once, which would cause conflicts.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 9th Dec 2008 21:36
Thanks, I will use them from now on but I think my problem is Im putting the files in the wrong folders, where do they go?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Dec 2008 22:04
Where do you have them? Maybe you should zip everything up and show us rather than have us guess ... again

Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 9th Dec 2008 22:07
I had that problem when I forgot to define the body of a method.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 9th Dec 2008 22:18
Im pretty sure you have given me enough information to work through the problem, it might have been the define thing, Ive just got to wait untill my son goes to bed before I can sort it properly.
Thanks everyone, especially IanM.
Ill update in a few hours when its sorted.
prasoc
15
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 9th Dec 2008 23:01
In your .cpp files, use #include on the header files, and in your main program use
and the same for the buttons class.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 9th Dec 2008 23:50
I think there maybe some black magic at work here.
Im trying IanM's stripped down example from above,
saving all files in the same place (where the original main file is)

I get:

>Main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Character::update(void)" (?update@Character@@QAEXXZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Character::Character(void)" (??0Character@@QAE@XZ) referenced in function _main
1>LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
1>Debug\test gdk.exe : fatal error LNK1120: 3 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\pc\My Documents\Visual Studio 2008\Projects\Project1\test gdk\test gdk\Debug\BuildLog.htm"
1>test gdk - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The only difference from IanM's example is that im using a Dark GDK -3D Game template then deleting everything and doing his example, would that make a difference?

I really think im missing something basic, like not saving them to the right place.
I done a tutorial in C# once and you had to add stuff to the solution explorer, do you have to do anything like that here?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Dec 2008 00:22 Edited at: 10th Dec 2008 00:23
Have you not added the .cpp files to the project?

If you haven't, then the compiler won't compile them and therefore won't be able to link them. You should also add the .h files to your project too so that the IDE can work out all of the dependencies in your code.

Here's an example of what one of my plug-in projects looks like


Attachments

Login to view attachments
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 10th Dec 2008 00:36
Thanks again IanM, I eventualy got your example to work as a cosole application.
I was just adding files from the file menu, now I add a class from the solution explorer and that worked (and is quicker).
Cant get same example to work in Dark GDK 3D-Game template yet,
its defeated me for tonight(its late) but I am getting really close
and will try again tomorrow.
I cant believe I was doing stuff so wrong.
Thanks for all your time IanM.
Ill crack this tomorrow and then I can get on with the good stuff.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Dec 2008 14:52
No problem. If you still have problems later, and you don't mind me seeing your code, just zip everything up and email it to me - just remove the .ncb file and the release or debug folderfrom the zip before you send it.

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 10th Dec 2008 22:35
Completely sorted now, I wasn't adding my files to my project in solution explorer, learned the hard way but thats computers.
Also learned alot from your help on this thread.
Thanks, can't thank you enough, all I can do is keep an eye on this forum and help as many people as I can who may know less than me (if thats possible).

Login to post a reply

Server time is: 2024-09-30 13:19:27
Your offset time is: 2024-09-30 13:19:27