[FIXED] Modifying Irrlicht, Unresolved external symbol

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
ngvincent
Posts: 5
Joined: Sat Jan 14, 2012 6:24 am

[FIXED] Modifying Irrlicht, Unresolved external symbol

Post by ngvincent »

I'm interesting in adding functionality to the Irrlicht code to get the Kinect working easier (Microsoft Official Kinect SDK Beta 2)

However, I'm not used to using Visual Studio 2010 and my C++ skills are a little rusty. 2010 forces a Project Conversion process, but everything seems to be working before I started on this new class (CIrrDeviceKinect.cpp)

From my compiling/building/linking process for Irrlicht, I see the output below, and a CIrrDeviceKinect.obj

Code: Select all

 
1>  Generating Code...
1>  Compiling...
...
1>  CIrrDeviceKinect.cpp
...
1>  Starting pass 2
...
1>       CIrrDeviceKinect.obj
...
 
 
During the Build/link process for my code, I see that CIrrDevice isn't being found in Irrlicht.lib (while other functions like createDevice() are found)

Code: Select all

 
2>      Searching C:\Users\vtakng\Documents\git\irrlicht-x64-kinect\lib\Win64-visualstudio\Irrlicht.lib:
2>        Found __imp_createDevice
2>          Referenced in main.obj
2>          Loaded Irrlicht.lib(Irrlicht.dll)
2>        Found __IMPORT_DESCRIPTOR_Irrlicht
2>          Referenced in Irrlicht.lib(Irrlicht.dll)
2>          Loaded Irrlicht.lib(Irrlicht.dll)
2>        Found __NULL_IMPORT_DESCRIPTOR
2>          Referenced in Irrlicht.lib(Irrlicht.dll)
2>          Loaded Irrlicht.lib(Irrlicht.dll)
2>        Found Irrlicht_NULL_THUNK_DATA
2>          Referenced in Irrlicht.lib(Irrlicht.dll)
2>          Loaded Irrlicht.lib(Irrlicht.dll)
 
When I try to build my code, I get a

Code: Select all

2>main.obj : error LNK2019: unresolved external symbol "public: __cdecl irr::CIrrDeviceKinect::CIrrDeviceKinect(void)" (??0CIrrDeviceKinect@irr@@QEAA@XZ) referenced in function main
2>..\..\bin\Win64-VisualStudio\19.MouseAndJoystick.exe : fatal error LNK1120: 1 unresolved externals
If I DON'T use an extra .cpp file and put everything inside IEventReceiver.h, then there is no erorr





Code I added is
IEventReceiver.h, inside the namespace irr at the end

Code: Select all

class CIrrDeviceKinect 
        {
        public:
                //CIrrDeviceKinect(int id, irr::IrrlichtDevice* p, DWORD flags);
                CIrrDeviceKinect();
                ~CIrrDeviceKinect(){}
        
        };
New CIrrDeviceKinect.cpp

Code: Select all

namespace irr
{
CIrrDeviceKinect::CIrrDeviceKinect()
{
 
}
}
Last edited by ngvincent on Mon Jan 16, 2012 2:27 am, edited 1 time in total.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Linker is not linking .obj to .lib, help?

Post by mongoose7 »

Why are you changing the Irrlicht code? Why can't you put the file in your own space.

You don't really know C++ do you? It links when you put the definition in the header file but the function is empty, so it is completely pointless. Why don't you try to build your code a million miles away from Irrlicht and just call the Irrlicht functions that you need.
ngvincent
Posts: 5
Joined: Sat Jan 14, 2012 6:24 am

Re: Linker is not linking .obj to .lib, help?

Post by ngvincent »

The kinect is more of a hardware device, and I want it to act more like the joyStick or mouse (callbacks/Events through the engine)... thought it would be neater than running it along with my own code

I haven't touched C++ in over a year. I know it links when I put the definition in, but it should be fine even if the function is empty (but its not). The function is empty because I remove the non-essential stuff

anyways, I'll move the code away from the irrlicht namespace then...
ngvincent
Posts: 5
Joined: Sat Jan 14, 2012 6:24 am

Re: Linker is not linking .obj to .lib, help?

Post by ngvincent »

I think I know what is happening...

Default Irrlicht (Windows in Visual Studio [2010]) compiles as a dynamic library... the compiled library has to know where to dynamically link the objects/dll.... <- my new code is failing at this step

When I switch everything over to a static library, my code compiles without any problem (more accurately, the Irrlicht lib always compiles fine with whatever I do. MY test code in another project will have problems compiling, getting the UNRESOLVED SYMBOL ERROR for CIrrDeviceKinect::CIrrDeviceKinect() if I compile as a dynamic lib)

SOLUTION
THIS ONLY HAPPENS if you try to add your code into the Irrlicht library(so that you code gets compiled into the Irrlicht.lib / Irrlicht.dll)

EDIT: Fixed my problems with the dynamic library. Solution below if anyone is interested

-- have to export the names and include them in the.lib file via __declspec(dllexport)
IRRLICHT_API <- does that. It appears in the IrrCompileConfig.h file, activated if the _IRR_STATIC_LIB_ IS NOT defined

Code: Select all

// To build Irrlicht as a static library, you must define _IRR_STATIC_LIB_ in both the
// Irrlicht build, *and* in the user application, before #including <irrlicht.h>
#ifndef _IRR_STATIC_LIB_
#ifdef IRRLICHT_EXPORTS
#define IRRLICHT_API __declspec(dllexport)
#else
#define IRRLICHT_API __declspec(dllimport)
#endif // IRRLICHT_EXPORT
#else
#define IRRLICHT_API
#endif // _IRR_STATIC_LIB_
My new code:

Inside IEventReceiver.h

Code: Select all

class IRRLICHT_API CIrrDeviceKinect 
        {
        public:
                 CIrrDeviceKinect();
                ~CIrrDeviceKinect(){}
        
        };
Inside another .cpp file

Code: Select all

 
CIrrDeviceKinect::CIrrDeviceKinect()
{
 
}
 
Breakpoints and stepping through using Visual Studio shows the code going through the right process
Last edited by ngvincent on Mon Jan 16, 2012 6:00 am, edited 2 times in total.
Post Reply