Wow, quite a bump, but it's not as if this doesn't deserve a little more spotlight. I have a question that should be easy to solve, but hard to pose.
I quickly discovered that defining classes in one file and everything else in main() created some serious restrictions. A bit of searching brought me to IrrWizard, and it has got to be the most beautiful example of program structure I've seen (not that I've seen too many
). So I went about deconstructing the structure and building it up from scratch to understand it. I hit some serious walls, but using the output of IrrWizard as something of a cheat sheet, I've got it pretty much straightened out.
It's an incredibly bare-bones version, and probably won't even display anything when it runs, but I'm just trying to get all my files in order and compiling first. The thing is they compile happily (a minor miracle in itself) , but I hit just a couple of linker errors. They're your basic 2019s and 2001s, but I'm pretty sure I've included everything I can and have a suspicion it's something specifically to do with all the #including and calling between sources that's giving me trouble.
So here's my linker output:
Code: Select all
1>Linking...
1>CGame.obj : error LNK2019: unresolved external symbol "public: class irr::IrrlichtDevice * __thiscall CGameManager::getDevice(void)" (?getDevice@CGameManager@@QAEPAVIrrlichtDevice@irr@@XZ) referenced in function "public: bool __thiscall CGame::Run(void)" (?Run@CGame@@QAE_NXZ)
1>CGamePlayStateDefault.obj : error LNK2001: unresolved external symbol "public: class irr::IrrlichtDevice * __thiscall CGameManager::getDevice(void)" (?getDevice@CGameManager@@QAEPAVIrrlichtDevice@irr@@XZ)
1>CGamePlayStateDefault.obj : error LNK2019: unresolved external symbol "public: class irr::video::IVideoDriver * __thiscall CGameManager::getDriver(void)" (?getDriver@CGameManager@@QAEPAVIVideoDriver@video@irr@@XZ) referenced in function "public: virtual void __thiscall CGamePlayState::Init(class CGameManager *)" (?Init@CGamePlayState@@UAEXPAVCGameManager@@@Z)
1>C:\Users\Oliver\Documents\Visual Studio 2008\Projects\Tango3D\Debug\Tango3D.exe : fatal error LNK1120: 2 unresolved externals
They're all problems with methods of CGameManager, but I've gone through many times and my version is basically identical to area51's, minus a bunch of features like gui, input, sound, enemies, items, fx... y'know, the minor things
The files I've got are the .h's and .cpp's of CGame, CGameManager, CGameState, CGamePlayState, and CGamePlayStateDefault (the equivalent of Level01), and a main.cpp. Basically everything relevant that appears in their IrrWizard equivalents (no C in filenames) is present, with everything referring to other files removed.
I figure, as with seemingly all linker errors, the first reaction would be to include missing .lib's, but I've got a #pragma comment(lib, "Irrlicht.lib") in main.cpp (as per IW), and the full path to Irrlicht.lib in my linker's additional dependencies, as well as the Irrlicht include directory as an include dependency. Something else to note is that the getDevice() and getDriver() methods that seem to be sources of problems when called from elsewhere are marked as inline, which I have only a passing understanding of and have read has to do with linkers in some situations.
EDIT: Basically, the getDevice() and getDriver() methods of CGameManager are throwing linking errors 2001 or 2019 when called from other classes, HOWEVER this can be resolved by merging the definition and declaration into the header, rather than defining said accessors in the .cpp. However the getSceneManager method works fine, and it's basically identical to getDriver, in that it does the same thing and the scene manager pointer was created the same way as the driver pointer.
[/EDIT]
SO! Long-winded introduction to a (hopefully) pretty simple error. Linkers always confuse the hell out of me, possibly in part because simply factoring code in C++ forces me to think pretty hard
. Any idea what to include? Or fix? Need more information?
As a last word, I gotta say again this a beautiful framework, and its taught me more about game structure programming than whatever Google turned up. I can't wait to pick learn JP's IrrPhysx and try and plug that in as a physics manager!