Compile to library issue

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
StaticAres
Posts: 19
Joined: Sun Nov 16, 2008 6:12 pm

Compile to library issue

Post by StaticAres »

*Info
- Windows XP
- Visual Studio 2008
- Microsoft DirectX SDK (June 2008)

*Problem
Compiling Irrlicht as .lib is succesfull. But, when compiling the application that is going to make use of irrlicht the following error occurs:

Code: Select all

error LNK2019: unresolved external symbol "__declspec(dllimport) class irr::IrrlichtDevice * __cdecl irr::createDevice(enum irr::video::E_DRIVER_TYPE,class irr::core::dimension2d<int> const &,unsigned int,bool,bool,bool,class irr::IEventReceiver *,char const *)" (__imp_?createDevice@irr@@YAPAVIrrlichtDevice@1@W4E_DRIVER_TYPE@video@1@ABV?$dimension2d@H@core@1@I_N22PAVIEventReceiver@1@PBD@Z) referenced in function _main
I do link .lib file. Im a little stuck now, thinking that it is the compilation process that fails.

Any tips or hints?
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Check if you really link the correct lib and not accidently the one for gcc.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
StaticAres
Posts: 19
Joined: Sun Nov 16, 2008 6:12 pm

Post by StaticAres »

CuteAlien wrote:Check if you really link the correct lib and not accidently the one for gcc.
Im linking to the library i build.
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

StaticAres wrote:
CuteAlien wrote:Check if you really link the correct lib and not accidently the one for gcc.
Im linking to the library i build.
Check again ;-) And do check some more - is the lib really updated after you compiled the engine (check the date). Do you use the correct headers (though probably not the problem).

You error is not in compilation but in linking. And in short it says that it does not find the function implementation. That means either you link not to the correct lib, or maybe you link to the lib but it got compiled with another header where this function had for example other parameters and so it's not found now.

Another check you can do to be really sure it's using that lib. Delete/rename it for a moment - you should get another error now.

Also - is this the only error you get?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Re: Compile to library issue

Post by rogerborg »

StaticAres wrote:Compiling Irrlicht as .lib is succesfull.
Can you clarify what you mean by this?

The standard Irrlicht Windows builds produce an Irrlicht.lib and an Irrlicht.dll. You can build Irrlicht as a static library; is this what you are doing?

If not, then what (if anything) are you doing that is different from the SDK build process?

If you open the (unmodified) /examples/BuildAllExamples_v9.sln, then build the Irrlicht project, then any of the examples, everything Should Just Work (tm). If not, please let us know exactly what you have changed in order to wreak havoc on our beautiful, perfect build.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
StaticAres
Posts: 19
Joined: Sun Nov 16, 2008 6:12 pm

Re: Compile to library issue

Post by StaticAres »

@CuteAlien, already did a couple things. Ill keep looking.

@rogerborg, im building irrlicht as a static library.

@both, ill try everything tommorow. If I still can't make it work, ill report back. Thanks for the quick reponses.
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Make sure you are compiling both the lib and your application with the same runtime library setting (In the C++/Code Generation page of Project Settings, choose either /MT or /MD for release and /MTd or /MDd for debug). If you compile them with different settings, then it's very likely you will run into odd linker errors.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Make sure that you enable the STATIC library build define, otherwise the symbols are not properly defined under Windows...
StaticAres
Posts: 19
Joined: Sun Nov 16, 2008 6:12 pm

Post by StaticAres »

is the lib really updated after you compiled the engine (check the date). Do you use the correct headers (though probably not the problem).
Both, yes.
You error is not in compilation but in linking. And in short it says that it does not find the function implementation. That means either you link not to the correct lib, or maybe you link to the lib but it got compiled with another header where this function had for example other parameters and so it's not found now.
Tested, not the problem.
Another check you can do to be really sure it's using that lib. Delete/rename it for a moment - you should get another error now.
Yes, I get a error telling me that the lib cannot be found.
Also - is this the only error you get?
It is.
/MT or /MD for release
Tried, didn't work.
enable the STATIC library build define
If you mean,
Visual Studio -> Configuration Type -> Static Library (.lib),
Yes, im defining static library.

Its maiby a little odd to request, but, if someone got some time on hands, could he or she try to compile the irrlicht engine with the same setup as I have?

ps. Tried on windows Vista today, same problem/errors. (re-downloaded irrlicht sdk, re-setup environment settings)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, Irrlicht requires some defines to properly compile to and with a static library. This is not very much supported under Windows, hence it won't work automatically. Jsut brwose IrrCompileConfig.h and check which things alter the static library compilation.
StaticAres
Posts: 19
Joined: Sun Nov 16, 2008 6:12 pm

Post by StaticAres »

hybrid wrote:No, Irrlicht requires some defines to properly compile to and with a static library. This is not very much supported under Windows, hence it won't work automatically. Jsut brwose IrrCompileConfig.h and check which things alter the static library compilation.
I will. Thanks for the tip.

*Edit
Can't find anything that might help. Do you ment something specific in IrrCompileConfig.h?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

It's not at all obvious, but _IRR_STATIC_LIB_ needs to be defined in both the Irrlicht build, and in the user application build (before Irrlicht.h is included).

I've just committed a comment to this effect in IrrCompileConfig.h, along with static lib build configurations in the VS solutions/project files.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
StaticAres
Posts: 19
Joined: Sun Nov 16, 2008 6:12 pm

Post by StaticAres »

rogerborg wrote:It's not at all obvious, but _IRR_STATIC_LIB_ needs to be defined in both the Irrlicht build, and in the user application build (before Irrlicht.h is included).

I've just committed a comment to this effect in IrrCompileConfig.h, along with static lib build configurations in the VS solutions/project files.
Thank you!, its sort of working, ill figure out the rest.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

StaticAres wrote:Thank you!, its sort of working, ill figure out the rest.
I'd like it to be completely working. Can you detail what's still not working for you, and we'll get it sorted.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
StaticAres
Posts: 19
Joined: Sun Nov 16, 2008 6:12 pm

Post by StaticAres »

rogerborg wrote:
StaticAres wrote:Thank you!, its sort of working, ill figure out the rest.
I'd like it to be completely working. Can you detail what's still not working for you, and we'll get it sorted.
Error:

Code: Select all

LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
The application does compile and run.

About the error,
i did a quick google and think that what Dark_Kilauea said about MT/MD is the solution. I can test it in a couple hours.


* Edit,
Irrlicht has /MT defined. Define /MT in the application solves the error. Compilation is quite slow, but no errors anymore.
Post Reply