Page 1 of 2

Irrlicht Static Linking

Posted: Thu Jun 19, 2008 2:23 am
by ClassDev
For those how want use Irrlicht but doesn't like dist the app with a dll (like me) just do this.

Step 1. Recompile the Irrlicht Engine as static library
Step 2. Move the .lib (~48mb to lib dir)
Step 3. Before include irrlicht.h write "#define _IRR_STATIC_LIB_"

done. compile, and you will have your executable size around 1mb and without dlls :)

Regards and Nice Engine!

Posted: Thu Jun 19, 2008 8:49 am
by hybrid
If you don't want to change the irrlicht header files you can simply put this as a compiler option into your project file...

Posted: Wed Jun 17, 2009 11:30 am
by t0rt0r0
Hi !

Is it the same way to do this with Irrlicht 1.5 ?

Maybe my project is wrong, my link still crash (also my .a of irrlicht static is about 11mb and not 50mb so maybe i'm wrong when recompiling the engine :/)

If anyone has tried this with 1.5 ;)

Posted: Wed Jun 17, 2009 12:00 pm
by Brainsaw
I can't really help you as I didn't yet try to link Irrlicht as a static lib, but for the file size: it differs because you seem to be using gcc, because you have a "Irrlicht.a" whereas in the initial post there is a "Irrlicht.lib" mentioned.

Posted: Wed Jun 17, 2009 1:47 pm
by Murloc992
Working on latest SVN version. :) Well it requires to disable LIBCMT and increases compiling time A LOT it is still very very amazing founding. :)

Thanks for it!

EDIT: Even .exe opens/works in cosmic speed, great performance improvement. Worth of compiling time.

Posted: Wed Jun 17, 2009 1:58 pm
by Sylence
Are you trying to tell us that you note a difference in the startup time of an application because one DLL was replaced by a static library ?

Posted: Wed Jun 17, 2009 2:44 pm
by t0rt0r0
Brainsaw wrote:I can't really help you as I didn't yet try to link Irrlicht as a static lib, but for the file size: it differs because you seem to be using gcc, because you have a "Irrlicht.a" whereas in the initial post there is a "Irrlicht.lib" mentioned.
Yes i'm using gcc and Irrlicht 1.5 (i prefer don't use the svn for now).

So, nobody has tried it on 1.5 ? :'(

Posted: Wed Jun 17, 2009 6:33 pm
by hybrid
It works with 1.5 exactly as with 1.4 and 1.6

Posted: Wed Jun 17, 2009 7:54 pm
by t0rt0r0
Hum, so i'm wrong with my linking, i'll try again tomorrow but i still can't understand why Oo

thx all ;)

Posted: Wed Jun 17, 2009 9:07 pm
by Jookia
Sylence wrote:Are you trying to tell us that you note a difference in the startup time of an application because one DLL was replaced by a static library ?
Windows hasn't always been exceptional at optimizing stuff.

Posted: Wed Jun 17, 2009 11:36 pm
by Dorth
Jookia, that was a pretty dumb statement. Actually, it's pretty much the opposite. While some other OS did an even better job at it, considering the structure Windows offer to develloper and user, it does an AMAZING job at optimization. Please don't be a M$ basher for the fun of being one. I use to be one for so long. Then I actually learned what was the decisions behind so many things, the cleverness of so many hacks, the design process and so on. Sure, some apps of M$ are full of fail (Bob anyone?) but then again, every big power player have its own, may it be open-source or privatelly owned. Their blunders are just more apparent because they occupy so much space.

Posted: Tue Oct 13, 2009 7:14 pm
by wasup999999
I hate bumping old topics, but I'm able to compile Irrlicht 1.6 as a static library (producing libIrrlicht.a) but when I try to link my simple irrlicht program with this file, I get all sorts of linking errors:

Code: Select all

..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(CIrrDeviceWin32.o)||In function `_ZN3irr15CIrrDeviceWin327presentEPNS_5video6IImageEPvPNS_4core4rectIiEE':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\CIrrDeviceWin32.cpp|650|undefined reference to `_StretchDIBits@52'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\CIrrDeviceWin32.cpp|657|undefined reference to `_StretchDIBits@52'|
..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(CIrrDeviceWin32.o)||In function `_ZN3irr15CIrrDeviceWin3217activateJoysticksERNS_4core5arrayINS_13SJoystickInfoENS1_12irrAllocatorIS3_EEEE':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\CIrrDeviceWin32.cpp|1004|undefined reference to `_joyGetNumDevs@0'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\CIrrDeviceWin32.cpp|1018|undefined reference to `_joyGetPosEx@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\CIrrDeviceWin32.cpp|1018|undefined reference to `_joyGetDevCapsA@12'|
..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(CIrrDeviceWin32.o)||In function `_ZN3irr15CIrrDeviceWin3213pollJoysticksEv':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\CIrrDeviceWin32.cpp|1066|undefined reference to `_joyGetPosEx@8'|
..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(CIrrDeviceWin32.o)||In function `_ZN3irr15CIrrDeviceWin3212setGammaRampEfffff':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\CIrrDeviceWin32.cpp|1128|undefined reference to `_SetDeviceGammaRamp@8'|
..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(CIrrDeviceWin32.o)||In function `_ZN3irr15CIrrDeviceWin3212getGammaRampERfS1_S1_S1_S1_':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\CIrrDeviceWin32.cpp|1140|undefined reference to `_GetDeviceGammaRamp@8'|
..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(COpenGLDriver.o)||In function `_ZN3irr5video13COpenGLDriver10initDriverENS_27SIrrlichtCreationParametersEPNS_15CIrrDeviceWin32E':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|173|undefined reference to `_ChoosePixelFormat@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|178|undefined reference to `_SetPixelFormat@12'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|179|undefined reference to `_wglCreateContext@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|188|undefined reference to `_wglMakeCurrent@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|191|undefined reference to `_wglDeleteContext@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|198|undefined reference to `_wglGetProcAddress@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|266|undefined reference to `_wglMakeCurrent@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|267|undefined reference to `_wglDeleteContext@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|316|undefined reference to `_ChoosePixelFormat@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|323|undefined reference to `_SetPixelFormat@12'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|331|undefined reference to `_wglGetProcAddress@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|336|undefined reference to `_wglCreateContext@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|345|undefined reference to `_wglMakeCurrent@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|348|undefined reference to `_wglDeleteContext@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|352|undefined reference to `_GetPixelFormat@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|353|undefined reference to `_DescribePixelFormat@16'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|374|undefined reference to `_wglGetProcAddress@4'|
..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(COpenGLDriver.o)||In function `_ZN3irr5video13COpenGLDriverD2Ev':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|500|undefined reference to `_wglMakeCurrent@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|503|undefined reference to `_wglDeleteContext@4'|
..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(COpenGLDriver.o)||In function `_ZN3irr5video13COpenGLDriverD1Ev':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|500|undefined reference to `_wglMakeCurrent@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|503|undefined reference to `_wglDeleteContext@4'|
..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(COpenGLDriver.o)||In function `_ZN3irr5video13COpenGLDriverD0Ev':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|500|undefined reference to `_wglMakeCurrent@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|503|undefined reference to `_wglDeleteContext@4'|
..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(COpenGLDriver.o)||In function `_ZN3irr5video13COpenGLDriver17genericDriverInitERKNS_4core11dimension2dIjEEb':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|520|undefined reference to `_glGetString@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|527|undefined reference to `_glGetString@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|528|undefined reference to `_glGetString@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|550|undefined reference to `_glPixelStorei@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|553|undefined reference to `_glViewport@16'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|558|undefined reference to `_glLightModeli@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|560|undefined reference to `_glLightModeli@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|566|undefined reference to `_glClearDepth@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|567|undefined reference to `_glHint@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|568|undefined reference to `_glHint@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|569|undefined reference to `_glHint@8'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|570|undefined reference to `_glDepthFunc@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|571|undefined reference to `_glFrontFace@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|591|undefined reference to `_glAlphaFunc@8'|
..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(COpenGLDriver.o)||In function `_ZN3irr5video13COpenGLDriver8endSceneEv':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|663|undefined reference to `_glFlush@0'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|667|undefined reference to `_SwapBuffers@4'|
..\..\..\Irrlicht\irrlicht-1.6\lib\Win32-gcc\libIrrlicht.a(COpenGLDriver.o)||In function `_ZN3irr5video13COpenGLDriver12clearBuffersEbbbNS0_6SColorE':|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|707|undefined reference to `_glClearColor@16'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|715|undefined reference to `_glDepthMask@4'|
C:\Program Files\Irrlicht\irrlicht-1.6\source\Irrlicht\COpenGLDriver.cpp|723|undefined reference to `_glClear@4'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings ===|
I've tried a lot of things to get it working, doesn't change a thing. I'm using Code::Blocks and MinGW

Posted: Thu Oct 15, 2009 11:00 am
by hybrid
You have to link the win32 dlls and opengl dll on your own, which is otherwise linked in by the Irrlicht.dll.

Posted: Fri Oct 16, 2009 12:33 am
by wasup999999
It'd be really helpful if this was put on a FAQ or something (for people like me who aren't quite as seasoned at static libraries). I found out that (at least in windows using code::blocks) you have to link Irrlicht.a first (Irrlicht at the top of the list) before opengl32, gdi32, and winmm or it will not work.

Posted: Fri Oct 16, 2009 9:24 am
by hybrid
That's the usual thing for static libs. Object files and static libs are linked in as shown in the command line. Symbols which are not yet linked are not known and thus not linked. However, dlls and shared objects are always linked in, which would mean that it wouldn't matter if you put them somewhere else. Maybe Windows is different here, due to the .lib and .dll combination.