Sign in to follow this  
rjackets

unresolved external symbol?

Recommended Posts

I've use ODE (Open Dynamics Engine) in a previous test program that I have made and it worked quite well. However, now I am trying to implement it in a more complex engine and I am having difficulties. It's probably not a problem SPECIFIC to ODE, but I can't seem to find a solution. The problem is relatively simple. I can use the ODE routines and whatnot when NOT using them in a class, but if I try and implement it into a class suddenly the compiler complains that I'm trying to reference an unresolved external symbol! This seems odd to me since I would think if the compiler knows what it is when not in a class then it should know it in a class. I will give an example: This DOES work:
static void Initialize(void)
{
	dWorldCreate();
}


(note: I am aware that this call is pointless, but at the juncture I'm just trying to get it this far. This does NOT work (even though it is in exactly the same cpp file):
void CPhysics::Initialize(void)
{
	dWorldCreate();
}


The error I get is: error LNK2019: unresolved external symbol _dWorldCreate referenced in function "public: void __thiscall CPhysics::Initialize(void)" (?Initialize@CPhysics@@QAEXXZ) I appreciate any and all help provided. Thanks in advance. [Edited by - rjackets on September 1, 2005 11:14:40 AM]

Share this post


Link to post
Share on other sites
I honestly don't know the answer, sorry, but can offer a guess:
Is it possibly something to do with the first initialize function being declared static - I think that deprecated in c++, in preference for un-named namespaces??? Comment out that first function and try then.

Again its just guess, but worth a try :)

Share this post


Link to post
Share on other sites
Where's dWorldCreate() declared/defined? Different file, does it have external linkage? Did you forget to include a header file? The link error is telling you what the problem is. You have an undefined symbol. You need to make sure you let this bit of code know about your dWorldCreate() function.

Share this post


Link to post
Share on other sites
You probably declared the function dWorldCreate in the class body of CPhysics, but when you actually defined dWorldCreate you left off the CPhysics::. So the linker can find it as an unprototyped global function, but when you refer to it in a member function of CPhysics the declaration in the class body overrides the global definition and the linker tries to find a member version which has never been defined.

Share this post


Link to post
Share on other sites
Thanks for the replies, but it hasn't helped so far. The dWorldCreate() function is a member of the ODE library... which I am linking in my header file using
#include <ode/ode.h>
this is why this is particularly confusing. It obviously is able to detect the function when I put it in a static process, but not if its in a function. I dont see how an external library should have this problem. It's like linking to the directX SDK and only being able to detect the D3DXMatrixMultiply() function in a static function (for those familiar with Directx).
In response to dmatter, the two examples I gave were merely to illustrate the difference between the two ways I could do it. I neither want to use a static function, and I certainly am not trying to have both in there at the same time -- so it is not a problem with trying to reference the same function in two different way, but I can see how I may have been confusing there.

Share this post


Link to post
Share on other sites
Are you linking in this thirdparty library on your link line? Just cause you use a PCH approach, or include the header file doesn't mean that it will resolve the link issue. The linker is telling you it cannot find a symbol for the function you are referencing. That either means, you forward declared a pointer and forgot the include file in the C/CPP file (This isn't the case as it is a function it can't find). Or, you aren't linking in the static, dynamic, archive, etc... file. There is a difference between compiling and linking.

Share this post


Link to post
Share on other sites
ODE works fine in both C and C++. If you're including the headers, chances are you're not linking the code to the ODE libraries. Take ArmitageIII87's advice and do the linking, 'cause that should fix the problem.

Share this post


Link to post
Share on other sites
I've done the linking and I've linked just about every possible thing to do with ODE. I eventually took the project settings from the old program I mentioned and now it seems to work fine. I think your right that it was a problem with it not finding a library or something that it needed, but I'm stumped as to which particular one. I must have got it last time though and it's working now. Thanks for the help anyway!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this