Jump to content
  • Advertisement
Sign in to follow this  
Jesse Dager

class problems

This topic is 1917 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

I am trying to create a basic class to go with my project, and I keep getting the error "unresolved external symbol." I have no idea what is causing it.

 

I use VC++ 2010 express

 

JEngine.h

#ifndef JENGINE_H
#define JENGINE_H

#include "stdafx.h"

class JEngine
{
public:
	void Initialize();

};
#endif


JEngine.cpp

#include "JEngine.h"
#include "stdafx.h"

void JEngine::Initialize()
{
}

 

 

 

main.cpp

#include "stdafx.h"
#include "JEngine.h"

int main(int argc, char **argv){
	
	JEngine* gameInstance = new JEngine();
	gameInstance->Initialize();
	return 1;
	
}

 

 

Share this post


Link to post
Share on other sites
Advertisement
Guest Hiwas

JEngine.cpp
 

#include "JEngine.h"
#include "stdafx.h"
 

 

Should be

 

JEngine.cpp
 

 

#include "stdafx.h"
#include "JEngine.h"

Eww, nice catch.  That is a nasty one to figure out.  But explaining what kicked ya in the butt is a good idea also...

 

What jelly caught is basically a problem with precompiled headers that will get you quite often.  A precompiled header is basically a memory dump of the symbol table at the point where the trigger file is accessed within the compile.  With "automatically generated by xxxx", the default in VC I believe, the symbol table dump is likely to be triggered at the start of the header for JEngine.h before the class is defined and included in the symbol table dump.  Reloading the symbol table overwrites anything which was already there and as such, in the cpp your class inclusion before the trigger include simply gets forgotten because the entire symbol table is loaded overwriting anything you may have already included.

 

This sounds confusing to me and I used to know it inside and out.  Just do as jelly mentions and it will fix it.  The details get pretty goofy. :)

Share this post


Link to post
Share on other sites

 

JEngine.cpp
 

#include "JEngine.h"
#include "stdafx.h"
 

 

Should be

 

JEngine.cpp
 

 

#include "stdafx.h"
#include "JEngine.h"

Eww, nice catch.  That is a nasty one to figure out.  But explaining what kicked ya in the butt is a good idea also...

 

What jelly caught is basically a problem with precompiled headers that will get you quite often.  A precompiled header is basically a memory dump of the symbol table at the point where the trigger file is accessed within the compile.  With "automatically generated by xxxx", the default in VC I believe, the symbol table dump is likely to be triggered at the start of the header for JEngine.h before the class is defined and included in the symbol table dump.  Reloading the symbol table overwrites anything which was already there and as such, in the cpp your class inclusion before the trigger include simply gets forgotten because the entire symbol table is loaded overwriting anything you may have already included.

 

This sounds confusing to me and I used to know it inside and out.  Just do as jelly mentions and it will fix it.  The details get pretty goofy. smile.png

This did not fix the problem... I am still confused!

Share this post


Link to post
Share on other sites

More on precompiled headers in VS...

 

#include "stdafx.h"

 

must be the first line of code in each cpp file, it ignores everything until it sees the precompiled header include.

 

What error are you now getting? A few guesses

 

1) It's moaning about wmain or WinMain -> wmain means you have compiled the program using the Unicode char set instead of ANSI charset, this is in the options for the project. If it moans about WinMain, you didn't make a console project, make a new project that is a console app.

 

2) It worked, but after running it said there was an error. Don't return 1 from main, return 0 instead.

 

Those are just guesses though, please post the errors you are getting, not just "it doesn't work".

 

EDIT: Don't #include "stdafx.h" in header files either, that could be your problem...

Edited by Paradigm Shifter

Share this post


Link to post
Share on other sites
Guest Hiwas

Good clarifications Para, I remember the problems but not the specifics anymore.  I just don't use precompiled headers anymore and maintain low compile times without them.  :)  Of course doing that requires being an anal retentive prick about header design. :)

Share this post


Link to post
Share on other sites

Those are just guesses though, please post the errors you are getting, not just "it doesn't work".

 

 

Error 2 error LNK2019: unresolved external symbol "public: void __thiscall JEngine::Initialize(void)" (?Initialize@JEngine@@QAEXXZ) referenced in function _main C:\Users\Seth Hope\Documents\Visual Studio 2010\Projects\JcamEngine2\JcamEngine2\Jengine2.obj JcamEngine2
 
That's the error I get.
 
[edit] Here is the modified code. It still throws that error.
 
JEngine.cpp
#include "stdafx.h"
#include "JEngine.h"


void JEngine::Initialize()
{
}

 

JEngine.h

 

#ifndef JENGINE_H
#define JENGINE_H

class JEngine
{
public:
	void Initialize();

};
#endif

 

main.cpp


#include "stdafx.h"
#include "JEngine.h"
}

int main(int argc, char **argv){

	JEngine* gameInstance = new JEngine();
	gameInstance->Initialize();

	return 0;
	
}

 

 

 
Edited by sethhope

Share this post


Link to post
Share on other sites

Try cleaning and doing a full rebuild. Do you really need the precompiled headers?

Edited by Khatharr

Share this post


Link to post
Share on other sites

In visual studio, in the Solution Explorer, expand the option marked "Source Files" and see if JEngine.cpp is in it. If not, right click "Source Files" and go to Add -> Existing Item and find JEngine.cpp with the file explorer. Build and run.

Edited by Shaquil

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!