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

Glad you got it working! To fix those errors make sure you have the necessary files in either Data or CoreData (they should be in bin/*Data/

Other than that, the only thing I would recommend is that you use Urho’s log macros (in IO/Log.h) rather than std::cout in general so that the redirection to a file and such will all be handled uniformly.

1 Like

I will save my Makefile for the future. Maybe it will useful for beginners. If you want to use VSCode install the C/C++ for Visual Studio Code plugin. Press Ctrl+Shift+P and select C/C++: Edit Configurations (UI). Open the .vscode/c_cpp_properties.json file and include path to the Urho3D include folder:

            "includePath": [
                "${workspaceFolder}/**",
                "E:/Libs/Urho3D-1.7.1-MinGW-SHARED/include"
            ],

Makefile


CC = g++

INC = -I"E:\Libs\Urho3D-1.7.1-MinGW-SHARED\include"

LIB = -L"E:\Libs\Urho3D-1.7.1-MinGW-SHARED\lib\Urho3D"

FLAGS = -c

all: main.o
	$(CC) main.o -Wall -g -std=c++11 $(LIB) -lUrho3D -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -lSetupapi -ladvapi32 -lwinmm -limm32 -lversion -lws2_32 -ldbghelp -lopengl32 -o app

main.o: main.cpp
	$(CC) main.cpp $(FLAGS) $(INC)

Create a minimal file:

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)

Build the project: mingw32-make

3 Likes

My step-by-step tutorial for beginners: [Tutorial] How to set up Urho3D (Shared, MinGW) in Qt Creator IDE

1 Like

I tried to build Urho3D statically from source using CMake and MinGW32 but it is really looks like it cannot find the libUrho3D.a. Because I tried to delete “-lUrho3D” from settings and I get 21 errors like:

image

My settings:

CONFIG += c++11

INCLUDEPATH += "C:\Users\8Observer8\Downloads\Urho3D-1.7.1\dist\include"

LIBS += -L"C:\Users\8Observer8\Downloads\Urho3D-1.7.1\dist\lib"

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

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

SOURCES += \
    main.cpp

I want to mention that if I delete -lUrho3D I get 21 errors and if I do not delete -lUrho3D from settings above I get the same 21 errors in any case. This path is correct: C:\Users\8Observer8\Downloads\Urho3D-1.7.1\dist\lib:

image

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)