How to use Irrlicht with QT (MinGW + MSVC)

A forum to store posts deemed exceptionally wise and useful
Post Reply
Bonaducci
Posts: 11
Joined: Fri Aug 03, 2012 1:22 am
Location: Wrocław, Poland

How to use Irrlicht with QT (MinGW + MSVC)

Post by Bonaducci »

Qt has two compiler versions. It can compile using Visual C++ (2008 or 2010) if installed or MinGW.

Precompiled version:
For both of them it works fine, I can create simple tutorial how to do it if somebody wants, but it is very simple and MSVC similar. Only one difference is that we should use Qt '.pro' file to use various things. To be not groundless, there's solution.
1. Let's say, that we have workspace location named "Qt_Irrlicht". Qt Creator will propose subfolder named "src" for your source files. It's the best solution.
2. After creating the project, go to this location and create "irrlicht" folder. Simply paste there header files from "include" folder from irrlicht release and libs from "lib" folder appropriate to your compiler (MSVC or MinGW/gcc).
3. There is one trick. You can add manually all Irrlicht files to your project, but it's quite messy (for precompiled version it's ok, but for source with several subfolders it would be nightmare). On addition, manually added files will be merged with your own source and header files and it will be problematic to move around your project.
The best way to use this files is to create Qt ".pri" file. Create empty file in "irrlicht" subfolder with another Irrlicht files and name it "irrlicht.pri". Structure of this file is following:

Code: Select all

 
INCLUDEPATH += $$PWD
 
HEADERS += \
    $$PWD\aabbox3d.h \
    $$PWD\CDynamicMeshBuffer.h \
    $$PWD\CIndexBuffer.h \
    $$PWD\CMeshBuffer.h \
    $$PWD\coreutil.h \
    $$PWD\CVertexBuffer.h \
    $$PWD\dimension2d.h
Of course, you have to list all the header files from "irrlicht" folder in this files. This is only example. You can use both slash and backslash in datapath but it's better to use backslash '\'. As you can see, every but last line after HEADERS has backslashes at the end. This is quite problematic idea, but... We can deal with that. By the way, if you have source files in included directory (Bullet Physics compiled from the source for example) you can add after headers list this part:

Code: Select all

SOURCES += \
    $$PWD/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp \
    $$PWD/BulletCollision/BroadphaseCollision/btBroadphaseProxy.cpp \
    $$PWD/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.cpp \
    $$PWD/BulletCollision/BroadphaseCollision/btDbvt.cpp \
    $$PWD/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp \
    $$PWD/BulletCollision/BroadphaseCollision/btDispatcher.cpp \
    $$PWD/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp \
    $$PWD/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp \
    $$PWD/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp \
    $$PWD/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp
And as you can see, subdirectories are indexed as well.

I'm using quite fast method to do that. Windows command:

Code: Select all

 dir /s/b > index.txt
It will make index of all files in current directory and all directories with full path. Then you can use for example notepad++ and filter this files quite fast.
Usefull REGEXP for removing unwanted files. Choose replace and regexp from bottom, then replace this with empty phrase. Every line is another replace phrase:
".h" files

Code: Select all

^.+[^h]$
^.+[^\.]h$
".cpp" files

Code: Select all

^.+[^p]$
^.+[^p]p$
^.+[^c]pp$
^.+[^\.]cpp$
I think, that it's quite easy and don't need more explanation.
4. When you have it done, open Qt Creator, open your ".pro" file from the project tree and paste

Code: Select all

include(irrlicht/irrlicht.pri)
Then suddenly you'll have fully working subdirectory in your project detached from your own source and header files.
Image
(Yes, this is Polish)
5. Next step is to add precompiled libraries. You've pasted them already to the "irrlicht" directory, so the only thing to do is paste second thing to your ".pro" file.

Code: Select all

INCLUDEPATH += $$PWD/irrlicht \
DEPENDPATH += $$PWD\irrlicht \
unix:!symbian|win32: LIBS += -L$$PWD/irrlicht/ -lIrrlicht
It works for "irrlicht.lib" and "libirrlicht.a" both. You can simply add "-lIrrlichtKlang" to use this library from the same directory, if you'd like to.
6. After that you should add to your "main.cpp" this line and try to compile it in release/debug mode. It should compile with no errors (if this library has no errors)

Code: Select all

#include <irrlicht/irrlicht.h>
7. You can also use "irrlicht" folder in another directory and include it with full paths, for example

Code: Select all

 
!unix:!symbian|win32: LIBS += -LD:\Development\CUDA_SDK\OpenCL\common\lib\Win32 -lOpenCL
INCLUDEPATH += \
    D:\Development\CUDA_SDK\OpenCL\common\inc \ #cl_gl
    D:\Development\CUDA_SDK\CUDALibraries\common\inc \ #glut
DEPENDPATH +=  \
    D:\Development\CUDA_SDK\OpenCL\common\lib\Win32 \
It works for me too.
8. last thing. Put precompiled '.dll' files for your compiler version (MSVC or MinGW/gcc) in release / debug build location (where you '.exe' is going to show)
For example: "Qt_Irrlicht-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Release/release". It's standard name of folder which you can find in your workspace after first release compilation.

Now you should compile and run them from Qt Creator. Probably you can't still run them directly, because you have to use Qt dll's too. Default dll's are:

Code: Select all

Irrlicht:
    Irrlicht.dll
 
QT:
    libgcc_s_dw2-1.dll
    mingwm10.dll
    
Debug:
    QtCored4.dll
    QtGuid4.dll
    QtOpenGLd4.dll
    
Release:
    QtCore4.dll
    QtGui4.dll
    QtOpenGL4.dll
So there you go. It should work just fine for precompiled libraries.

Compiling from source:
Irrlicht release has both MSVC and MinGW/gcc project versions.
For MSVC it's not problem. Assuming that you have your Qt SDK configured right for MSVC, you have proper version of MSVC installed (there is no Qt with build-in MSVC compiler, but you should know that reading this thread). So, you load your ".sln" project for your version and it should work. There are many tutorials for MSVC. I'm not going to describe that, because I don't use MSVC. Idea should be similar.
For MinGW/gcc the best idea is to compile it under Code::Blocks. Eventually I've installed Code::Blocks (don't need to install build-in MinGW) and it works fine.
After installing it, go to Settings\Compiler and Debugger settings\Toolchain executabled. Then choose the same compiler you are using with Qt. Make sure, you have "g++.exe" set as default C++ compiler.
Image
After that you should be able to create dll's and libraries (simply build all) for your compiler. For created files check "bin" and "lib" directories, it should appear there (magic).
Post Reply