[Solved] Building a simple example using MinGW from command line

Since MinGW is just GCC you could #pragma push those macros in case you need them later. You probably don’t but a mere suggestion.

#if defined (__MINGW32__) || defined (__MINGW64__)
#pragma push_macro("CreateDirectory")
#endif
#undef CreateDirectory
//...

And later if you need one:

#pragma pop_macro("CreateDirectory")

Although this probably complicates things more than it should :laughing:
Reason I included this suggestion is in case you do it in a global header.

1 Like

By Building from source do you mean using the supplied urho3d build setup?

I downloaded the Urho3D-1.7.1 archive here: https://github.com/urho3d/Urho3D/releases I used CMake-GUI to configure and generate a project. And I use the mingw32-make command to make libUrho3D.a.

These are my settings. I just deleted some importers:

Ok. I assume from this stage you go ahead to click the “Generate” button.

After it is done generating your build files, you navigate to your build directory and through CMD run

mingw32-make -f makefile install

Was that your procedure?

Yes, I clicked the Generate button. I opened the “dist” folder and opened CMD in the “dist” folder. I wrote the “mingw32-make” command. After 10 minutes of successful building I got libUrho3D.a in the folder: C:\Users\8Observer8\Downloads\Urho3D-1.7.1\dist\lib

I will try this command.

To use the command

mingw32-make -f makefile install

ensure that your properly set the value for CMAKE_INSTALL_PREFIX, it should be the directory you want Urho3D to be installed in

I think I must to run CMD as Admin:

image

It does not work again:

image

My settings in Qt Creator IDE:

CONFIG += c++11

INCLUDEPATH += "C:\Program Files (x86)\Urho3D\include"

LIBS += -L"C:\Program Files (x86)\Urho3D\lib"

LIBS += -lUrho3D -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
LIBS += -ldbghelp -limm32 -lversion -lwinmm -lws2_32

SOURCES += \
    main.cpp

I use QT Creator and below is my *.pro file setting

TEMPLATE = app
CONFIG -= console
CONFIG -= app_bundle
CONFIG -= qt

TARGET = HelloUrho

URHO_HOME = C:\urho3d\home

DEFINES += O2 NDEBUG
DEFINES += URHO3D_STATIC_DEFINE URHO3D_ANGELSCRIPT URHO3D_FILEWATCHER URHO3D_IK URHO3D_LOGGING URHO3D_LUA URHO3D_NAVIGATION URHO3D_NETWORK URHO3D_PHYSICS URHO3D_PROFILING URHO3D_THREADING URHO3D_URHO2D URHO3D_WEBP HAVE_STDINT_H

QMAKE_CXXFLAGS += -mtune=generic -std=gnu++11 -Wno-invalid-offsetof -march=native -msse3 -static -static-libgcc -static-libstdc++ -fno-keep-inline-dllexport -mstackrealign -fdiagnostics-color=auto

INCLUDEPATH += $${URHO_HOME}\include $${URHO_HOME}\include\Urho3D\ThirdParty $${URHO_HOME}\include\Urho3D\ThirdParty\Bullet $${URHO_HOME}\include\Urho3D\ThirdParty\Lua

LIBS += -L$${URHO_HOME}\lib -lUrho3D -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lsetupapi -lversion -luuid -lws2_32 -liphlpapi -lwinmm -lopengl32

SOURCES +=
HelloUrho.cpp

HEADERS +=
HelloUrho.h

See if it can be of any help

1 Like

But a few days ago I made the same steps (CMake and so on) with Allegro5 and it works:

INCLUDEPATH += "E:\Libs\allegro-5.2.7.0-mingw-32bit\include"

LIBS += -L"E:\Libs\allegro-5.2.7.0-mingw-32bit\lib"

LIBS += -lallegro_dialog-static -lallegro_main-static -lallegro-static
LIBS += -lopengl32 -lgdi32 -lole32 -lwinmm -lcomdlg32 -lpsapi -lshlwapi

SOURCES += \
    main.cpp

main.cpp

#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>

int main()
{
    ALLEGRO_DISPLAY *display;

    if (!al_init())
    {
        al_show_native_message_box(NULL, NULL, NULL, "Could not initialize Allegro 5", NULL, 0);
    }

    if (!al_install_keyboard())
    {
        al_show_native_message_box(NULL, NULL, NULL, "Could not install keyboard", NULL, 0);
    }

    display = al_create_display(800, 600);

    if (!display)
    {
        al_show_native_message_box(NULL, NULL, NULL, "Could not create Allegro Window", NULL, 0);
    }

    bool done = false;
    bool redraw = true;

    ALLEGRO_EVENT_QUEUE *queue;
    queue = al_create_event_queue();
    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_display_event_source(display));

    while (!done)
    {
        ALLEGRO_EVENT event;

        if (redraw && al_is_event_queue_empty(queue))
        {
            al_clear_to_color(al_map_rgb_f(0, 0, 0));
            al_flip_display();
            redraw = false;
        }

        al_wait_for_event(queue, &event);

        switch (event.type)
        {
            case ALLEGRO_EVENT_KEY_DOWN:
                if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
                {
                    done = true;
                }
                break;
            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                done = true;
                break;
        }
    }

    return 0;
}

It very complicated for me. I am not an expert in .pro files but I will try later. Thank you! But it is very strange that Urho3D does not work in my settings because Allegro5 works fine with the same steps and settings.

Is it possible to post the content of your main.cpp and any companion header file of your urho3d setup.

main.cpp

#include <Urho3D/Engine/Application.h>
#include <iostream>

class MyApp : public Urho3D::Application
{
public:
    MyApp(Urho3D::Context * context) : Urho3D::Application(context)
    {
    }

    virtual void Setup()
    {
        std::cout << "Setup" << std::endl;
    }
};

URHO3D_DEFINE_APPLICATION_MAIN(MyApp)

Using a Urho3D-1.7.1 build I was able to successfully reproduce the error and seems to have identified what was actually causing it. Below is the modified .pro file of QT Creator that should work

CONFIG += c++11

INCLUDEPATH += "C:\Program Files (x86)\Urho3D\include"

LIBS += -L"C:\Program Files (x86)\Urho3D\lib"

DEFINES += URHO3D_STATIC_DEFINE

LIBS += -lUrho3D -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
LIBS += -ldbghelp -limm32 -lversion -lwinmm -lws2_32 -lopengl32

SOURCES += \
    main.cpp

The first of the additions to your previous setting is DEFINES += URHO3D_STATIC_DEFINE. Personally I usually include all the Urho Defines used in building the lib, however, URHO3D_STATIC_DEFINE seems to be the minimum needed for the code in your main.cpp to run.

The next addition is -lopengl32 added after the last LIBS +=

With these modification I was able to build and run the main.cpp you posted without any error.

21 errors again:

CONFIG += c++11

INCLUDEPATH += "C:\Program Files (x86)\Urho3D\include"

LIBS += -L"C:\Program Files (x86)\Urho3D\lib"

DEFINES += URHO3D_STATIC_DEFINE

#INCLUDEPATH += "E:\Libs\Urho3D-1.7.1-MinGW-32bit\include"

#LIBS += -L"E:\Libs\Urho3D-1.7.1-MinGW-32bit\lib\Urho3D"

#LIBS += -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -lSetupapi -ladvapi32 -lwinmm -limm32 -lversion -lws2_32 -ldbghelp -lopengl32 -lurho3d

#LIBS += -lUrho3D -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32

#LIBS += -ldbghelp -limm32 -lversion -lwinmm -lws2_32 -lopengl32

LIBS += -lUrho3D -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32

LIBS += -ldbghelp -limm32 -lversion -lwinmm -lws2_32 -lopengl32

SOURCES += \
    main.cpp

image

I even tried to build to Static Release:

image

But in this case I got 51 errors:

image

image

image

image

image

image

image

Might I ask where did you get the MinGW you’re using?

From Qt: C:\Qt5\Tools\mingw810_32\bin