1

I use:

  • Qt 5.15.2 MinGW 32-bit Dynamic for Debug build
  • Ogre 13.1.1 MinGW Static build

There is a class called ApplicationContextQt that can help to use Qt with Ogre3D but I have errors:

47a689b0-2071-4a12-a430-677f9bfe8d03-image.png

This example is very simple:

main.cpp

#include "Ogre.h"
#include "OgreApplicationContextQt.h"
#include <QGuiApplication>

class MyTestApp : public OgreBites::ApplicationContextQt, public OgreBites::InputListener
{
public:
    MyTestApp();
    void setup();
    bool keyPressed(const OgreBites::KeyboardEvent& evt);
};

MyTestApp::MyTestApp() : OgreBites::ApplicationContextQt("OgreTutorialApp")
{
}

bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
{
    if (evt.keysym.sym == OgreBites::SDLK_ESCAPE)
    {
        getRoot()->queueEndRendering();
    }
    return true;
}

void MyTestApp::setup(void)
{
    // do not forget to call the base first
    OgreBites::ApplicationContextQt::setup();

}

int main(int argc, char *argv[])
{
    QGuiApplication qapp(argc, argv);
    MyTestApp app;
    app.initApp();
    app.getRoot()->startRendering();
    app.closeApp();
    return qapp.exec();
}
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem"

LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib"
LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib\OGRE"

LIBS += -lOgreBitesQtStatic
LIBS += -lOgreBitesStatic -lRenderSystem_GL3PlusStatic -lOgreGLSupportStatic -lOgreMeshLodGeneratorStatic -lOgreOverlayStatic -lOgrePagingStatic -lOgrePropertyStatic -lOgreRTShaderSystemStatic -lOgreVolumeStatic -lPlugin_BSPSceneManagerStatic -lPlugin_DotSceneStatic -lPlugin_OctreeSceneManagerStatic -lPlugin_OctreeZoneStatic -lPlugin_ParticleFXStatic -lPlugin_PCZSceneManagerStatic -lRenderSystem_GLES2Static -lRenderSystem_GLStatic -lOgreMainStatic -lOgreTerrainStatic -lCodec_STBIStatic -lzlibstatic
LIBS += -lSDL2main -lSDL2.dll -lfreetype -lpugixml
LIBS += -lopengl32 -lgdi32
8Observer8
  • 868
  • 10
  • 17
  • 2
    I'd recommend using CMake and letting it figure out the dependencies, as laid out [here](https://ogrecave.github.io/ogre/api/latest/setup.html#cmake). – Super-intelligent Shade Oct 27 '21 at 15:30
  • Thank you. But I want to understand why my example does not work. – 8Observer8 Oct 27 '21 at 15:53
  • Maybe someone tried, like me, to build Ogre3D with "CMake GUI" and use it with Qt in this way. – 8Observer8 Oct 27 '21 at 16:25
  • 1
    I tried this about a year ago and never quite got it to work with `qmake`. While it is technically almost certainly possible (especially as you're currently just seeing linking erros) I can say from personal experience that @InnocentBystander has a point. I moved to cmake and it worked pretty well afterwards. I have a minimum test-case example still available if that is interesting. – Joel Bodenmann Oct 27 '21 at 16:57
  • @8Observer8 the "understand" part is simple: you are missing the library that exports those undefined symbols. You can try going through all the Ogre libraries and figure out which one it is. Or perhaps Ogre documentation may be of help. Alternatively, you may find that one of the libraries you are linking against does already export those symbols, in which case you might be a victim of the [ordering problem](https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc). – Super-intelligent Shade Oct 27 '21 at 19:31
  • CMake should take care of all that for you, which is why I suggested it from the start. I've stopped using qmake long time ago and never looked back. – Super-intelligent Shade Oct 27 '21 at 19:34
  • @InnocentBystander I will try to switch from qmake to cmake in Qt Creator project setting. Ogre has 21 libraries and I added all of them. – 8Observer8 Oct 27 '21 at 19:50
  • 1
    I think Ogre just does not work with qmake. I created a new Qt project with CMake instead of qmake. I added this line to CMakeList.txt: `find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG)` I added a new variable OGRE_DIR (where OGREConfig.cmake is located). I reopened Qt Creator. This example works! – 8Observer8 Oct 27 '21 at 21:27
  • @8Observer8 great! Good luck with your project – Super-intelligent Shade Oct 28 '21 at 00:01
  • @8Observer8 you can post your own answer and mark it as accepted solution, so others can benefit as well. – Super-intelligent Shade Oct 28 '21 at 00:02
  • @InnocentBystander No, It is not a solution yet. I have this error: `Target "BootstrapCMakeQt5Cpp" links to target "ZLIB::ZLIB" but the target was not found.` and with "ZLIB::ZLIB". – 8Observer8 Oct 28 '21 at 00:14
  • @InnocentBystander I will publish my solution when I will find it. – 8Observer8 Oct 28 '21 at 00:16
  • @8Observer8 sounds like you need to install [zlib](https://www.zlib.net/). – Super-intelligent Shade Oct 28 '21 at 00:18
  • @InnocentBystander SDL2 and zlib were built with Ogre. They was installed automatically with Ogre via CMake GUI as static libraries. But I think it works for Dynamic but I use Static build. I am not familiar with CMake. How to add SDL2 and zlib to CMakeLists.txt as static libraries? – 8Observer8 Oct 28 '21 at 00:33
  • @InnocentBystander I get the same result with CMake, the same errors: https://forums.ogre3d.org/viewtopic.php?f=2&t=96468&p=551610#p551610 – 8Observer8 Oct 28 '21 at 23:07
  • @JoelBodenmann I get the same result with CMake, the same errors: https://forums.ogre3d.org/viewtopic.php?f=2&t=96468&p=551610#p551610 – 8Observer8 Oct 28 '21 at 23:08
  • Then back to my earlier comment. Figure out which lib exports those functions. And see if you have ordering problem. – Super-intelligent Shade Oct 29 '21 at 02:43
  • @InnocentBystander It was cmake who had to establish the correct order. I do not know how to change libs order in cmake. I will try it in qmake in the .pro file. `OgreApplicationContextQt.h` requires `OgreBites::ApplicationContextQt` but I already have added this lib: `LIBS += -lOgreBitesQtStatic`. I have only one lib for Qt `libOgreBitesQtStatic.a` – 8Observer8 Oct 29 '21 at 11:39

1 Answers1

0

You can try this one ?

INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites"
INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem"

DEPENDPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE"
DEPENDPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites"
DEPENDPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem"

LIBS += -L"E:/ProgramFiles/ogre-13.1.1/lib/OgreBitesQtStatic" -lOgreBitesQtStatic
LIBS += -L"E:/ProgramFiles/ogre-13.1.1/lib/OGRE" -lOgreBitesStatic
// OR ...
LIBS += "E:/ProgramFiles/ogre-13.1.1/lib/OgreBitesQtStatic/OgreBitesQtStatic.a"
LIBS += "E:/ProgramFiles/ogre-13.1.1/lib/OGRE/OgreBitesStatic.a"
// It just depends on the actual names of your libraries

// Same for the others unless their file location is decleared under system path. 
// If so, you can add that libraries like how you did with opengl

And it is nice to add PRE_TARGETDEPS macros too if you make changes on those libraries so often:

PRE_TARGETDEPS += "E:/ProgramFiles/ogre-13.1.1/lib/OgreBitesQtStatic.a"

You can replace "/"s with "" too.

And the problem with your pro file was: You added library paths as libraries. And then tried to add that libraries from system environment.