Unresolved external symbol?

Started by
4 comments, last by suliman 6 years, 3 months ago

Hi

Having coded alot, i still get stuck on these things sometimes. I've restarted an old project so I needed to clean it up, fixed paths etc before it could compile. I still have one compile error:


Error	1	error LNK2019: unresolved external symbol "public: void __thiscall gameInventory::setSingleSlot(class int2)" (?setSingleSlot@gameInventory@@QAEXVint2@@@Z) referenced in function "public: __thiscall gameInventoryMaster::gameInventoryMaster(void)" (??0gameInventoryMaster@@QAE@XZ)	

C:\Dropbox\PROJECT\code\games\racing\source\gameMaster.obj

May it be a circular include or something? The function "setsingleSlot" is defined in a file called "inventory.h" which i dont have any references to in my project, so im a little stuck here.

Any ideas?
Happy holidays ya'all!

Advertisement
18 minutes ago, suliman said:

Any ideas?

There is an argument-less constructor in the class gameInventoryMaster within which the method gameInventory::setSingleSlot is invoked. So look out for that.

24 minutes ago, suliman said:

May it be a circular include or something?

More an indirect include, i.e. an include in an included file or an include in an implementation file.

Cool! Commenting out that call allows for it to compile.

But what can be wrong here? That file (with the constructor for gameInventoryMaster) is included in all my project and those work without commenting out the call togameInventory::setSingleSlot(). Why is it now not allowed?

I moved the body of the contructor (of gameInventoryMaster) to the cpp file (from the h file) and now all projects compile. So im confused, what could have have done here? :)

Firstly, this is a linker error, not a compiler error, so the problem is in what is being passed to the linker not the compiler. Secondly, when you get a 'unresolved external symbol' error the linker is trying to connect the reference to the setSingleSlot function in the constructor code to the actual setSingleSlot function, but can't find said function. As for why moving the constructor body to the cpp file fixed the issue, does gameMaster.cpp contain code for the gameInventoryMaster class?

yes it does. I continued to clean up and now it works (even with the body in the h-file). 

I think I had a reference to an old version of it that was local and not the standardized version i now use (#include "file.h" instead of #include <file.h>).

This is one of my big problems with C/C++. It's so easy to get stuck on code administration (linking, include order, circle reference etc) It takes time (especially when reviving an old project that had a slightly different code architecture).

Thanks for your help!

This topic is closed to new replies.

Advertisement