Building a simple example using MinGW from command line

I have MinGW on Windows. I downloaded Urho3D-1.7.1-MinGW-STATIC and I placed the “include” and “lib” folders here:

  • E:\Libs\Urho3D-1.7.1-MinGW-STATIC\include
  • E:\Libs\Urho3D-1.7.1-MinGW-STATIC\lib\Urho3D

The “lib\Urho3D” folder contains the “libUrho3D.a” file.

I wrote a very simple example with minimal code to show that it compiles and works:

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

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)

I try to compile it using this command:

g++ main.cpp -I"E:\Libs\Urho3D-1.7.1-MinGW-STATIC\include" -L"E:\Libs\Urho3D-1.7.1-MinGW-STATIC\lib\Urho3D" -lUrho3D -o app.exe

I see a lot of errors like:

E:\Libs\Urho3D-1.7.1-MinGW-STATIC\lib\Urho3D/libUrho3D.a(SDL_winmm.c.obj):SDL_winmm.c:(.text+0x942): undefined reference to `_imp__waveOutGetNumDevs@0’

E:\Libs\Urho3D-1.7.1-MinGW-STATIC\lib\Urho3D/libUrho3D.a(SDL_winmm.c.obj):SDL_winmm.c:(.text+0x97b): undefined reference to `_imp__waveOutGetDevCapsW@12’

E:\Libs\Urho3D-1.7.1-MinGW-STATIC\lib\Urho3D/libUrho3D.a(SDL_winmm.c.obj):SDL_winmm.c:(.text+0xa32): undefined reference to `_imp__waveInAddBuffer@12’

I added this key -lwinmm and I do not see the error message related to SDL_winmm.c above.

What key do I need to solve this error:

E:\Libs\Urho3D-1.7.1-MinGW-STATIC\lib\Urho3D/libUrho3D.a(SDL_windowsframebuffer.c.obj):SDL_windowsframebuffer.c:(.text+0x38a): undefined reference to `_imp__DeleteObject@4’

I would strongly suggest using CMake to get all the build flags correct. If you wish to switch over to just the command line after that you can just run make with VERBOSE=1 and see what the actual commands to compile the project were.

Also, welcome to the community!

2 Likes

Welcome to the community!

I can offer some minor notes…
Building from the master branch on github is frequently recommended as it maintains good stability, and there have been a number of fixes since last release.

Possibly helpful to MingW users,

Here is a bit of code I was using in my app header to target MSW under MinGW and limit global namespace pollution and conflicts with Urho methods.
#pragma once
// Somewhat limit windows header namespace pollution.

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOSERVICE
#define NOMCX
#define NOIME
#define NONLS
#include <windows.h>
#undef CreateDirectory
#undef GetClassName
#undef GetProp
#undef RemoveProp
#undef SetProp
#endif
4 Likes

Thank you, guys!

My steps:

  1. I downloaded a source from the master branch.
  2. I run CMake GUI.
  3. I selected “MinGW Makefiles” and “Use default native compilers”
  4. I choose the “source” and “dist” folders.
  5. I pressed the “Configure” button. There are some warnings at the beginning that I do not understand:
Output Urho3D-master

CMake Deprecation Warning at CMakeLists.txt:31 (cmake_policy):
The OLD behavior for policy CMP0026 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.

CMake Deprecation Warning at CMakeLists.txt:35 (cmake_policy):
The OLD behavior for policy CMP0063 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.

The C compiler identification is GNU 8.1.0
The CXX compiler identification is GNU 8.1.0
Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-win32-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe
Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-win32-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe - works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-win32-dwarf-rt_v6-rev0/mingw32/bin/g++.exe
Check for working CXX compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-win32-dwarf-rt_v6-rev0/mingw32/bin/g++.exe - works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Performing Test IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE
Performing Test IS_TRIVIALLY_DEFAULT_CONSTRUCTIBLE - Success
Performing Test IS_TRIVIALLY_DESTRUCTIBLE
Performing Test IS_TRIVIALLY_DESTRUCTIBLE - Success
Performing Test IS_TRIVIALLY_COPY_ASSIGNABLE
Performing Test IS_TRIVIALLY_COPY_ASSIGNABLE - Success
Performing Test IS_TRIVIALLY_COPY_CONSTRUCTIBLE
Performing Test IS_TRIVIALLY_COPY_CONSTRUCTIBLE - Success
Looking for C++ include d3dcompiler.h
Looking for C++ include d3dcompiler.h - found
Looking for C++ include d3d9.h
Looking for C++ include d3d9.h - found
Looking for C++ include d3d11.h
Looking for C++ include d3d11.h - found
Looking for C++ include ddraw.h
Looking for C++ include ddraw.h - found
Looking for C++ include dsound.h
Looking for C++ include dsound.h - found
Looking for C++ include dinput.h
Looking for C++ include dinput.h - found
Looking for C++ include dxgi.h
Looking for C++ include dxgi.h - found
Looking for include files windows.h, xinput.h
Looking for include files windows.h, xinput.h - found
Performing Test HAVE_XINPUT_GAMEPAD_EX
Performing Test HAVE_XINPUT_GAMEPAD_EX - Failed
Performing Test HAVE_XINPUT_STATE_EX
Performing Test HAVE_XINPUT_STATE_EX - Failed
Found DirectX: TRUE found components: DInput DSound XInput
Looking for stdint.h
Looking for stdint.h - found
Looking for inttypes.h
Looking for inttypes.h - found
Looking for malloc.h
Looking for malloc.h - found
Looking for __sincosf
Looking for __sincosf - not found
Looking for malloc_usable_size
Looking for malloc_usable_size - not found
Looking for sincosf in m
Looking for sincosf in m - found
Performing Test HAVE_RTL_OSVERSIONINFOW
Performing Test HAVE_RTL_OSVERSIONINFOW - Success
Performing Test HAVE_GCC_WALL
Performing Test HAVE_GCC_WALL - Success
Performing Test HAVE_GCC_NO_STRICT_ALIASING
Performing Test HAVE_GCC_NO_STRICT_ALIASING - Success
Performing Test HAVE_GCC_WDECLARATION_AFTER_STATEMENT
Performing Test HAVE_GCC_WDECLARATION_AFTER_STATEMENT - Success
Performing Test HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT
Performing Test HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT - Success
Performing Test HAVE_GCC_ATOMICS
Performing Test HAVE_GCC_ATOMICS - Success
Performing Test HAVE_GCC_PREFERRED_STACK_BOUNDARY
Performing Test HAVE_GCC_PREFERRED_STACK_BOUNDARY - Success
Performing Test HAVE_GCC_WSHADOW
Performing Test HAVE_GCC_WSHADOW - Success
Performing Test HAVE_NO_UNDEFINED
Performing Test HAVE_NO_UNDEFINED - Success
Looking for immintrin.h
Looking for immintrin.h - found
Looking for sys/types.h
Looking for sys/types.h - found
Looking for stdio.h
Looking for stdio.h - found
Looking for stdlib.h
Looking for stdlib.h - found
Looking for stddef.h
Looking for stddef.h - found
Looking for stdarg.h
Looking for stdarg.h - found
Looking for memory.h
Looking for memory.h - found
Looking for string.h
Looking for string.h - found
Looking for limits.h
Looking for limits.h - found
Looking for strings.h
Looking for strings.h - found
Looking for wchar.h
Looking for wchar.h - found
Looking for ctype.h
Looking for ctype.h - found
Looking for math.h
Looking for math.h - found
Looking for iconv.h
Looking for iconv.h - found
Looking for signal.h
Looking for signal.h - found
Looking for 7 include files stdint.h, …, float.h
Looking for 7 include files stdint.h, …, float.h - found
Looking for M_PI
Looking for M_PI - found
Looking for sys/mman.h
Looking for sys/mman.h - not found
Looking for strtod
Looking for strtod - found
Looking for malloc
Looking for malloc - found
Looking for calloc
Looking for calloc - found
Looking for realloc
Looking for realloc - found
Looking for free
Looking for free - found
Looking for getenv
Looking for getenv - found
Looking for setenv
Looking for setenv - not found
Looking for putenv
Looking for putenv - found
Looking for unsetenv
Looking for unsetenv - not found
Looking for qsort
Looking for qsort - found
Looking for abs
Looking for abs - found
Looking for bcopy
Looking for bcopy - not found
Looking for memset
Looking for memset - found
Looking for memcpy
Looking for memcpy - found
Looking for memmove
Looking for memmove - found
Looking for memcmp
Looking for memcmp - found
Looking for strlen
Looking for strlen - found
Looking for strlcpy
Looking for strlcpy - not found
Looking for strlcat
Looking for strlcat - not found
Looking for _strrev
Looking for _strrev - found
Looking for _strupr
Looking for _strupr - found
Looking for _strlwr
Looking for _strlwr - found
Looking for strchr
Looking for strchr - found
Looking for strrchr
Looking for strrchr - found
Looking for strstr
Looking for strstr - found
Looking for itoa
Looking for itoa - found
Looking for _ltoa
Looking for _ltoa - found
Looking for _uitoa
Looking for _uitoa - not found
Looking for _ultoa
Looking for _ultoa - found
Looking for strtol
Looking for strtol - found
Looking for strtoul
Looking for strtoul - found
Looking for _i64toa
Looking for _i64toa - found
Looking for _ui64toa
Looking for _ui64toa - found
Looking for strtoll
Looking for strtoll - found
Looking for strtoull
Looking for strtoull - found
Looking for atoi
Looking for atoi - found
Looking for atof
Looking for atof - found
Looking for strcmp
Looking for strcmp - found
Looking for strncmp
Looking for strncmp - found
Looking for _stricmp
Looking for _stricmp - found
Looking for strcasecmp
Looking for strcasecmp - found
Looking for _strnicmp
Looking for _strnicmp - found
Looking for strncasecmp
Looking for strncasecmp - found
Looking for vsscanf
Looking for vsscanf - found
Looking for vsnprintf
Looking for vsnprintf - found
Looking for fopen64
Looking for fopen64 - found
Looking for fseeko
Looking for fseeko - found
Looking for fseeko64
Looking for fseeko64 - found
Looking for sigaction
Looking for sigaction - not found
Looking for setjmp
Looking for setjmp - not found
Looking for nanosleep
Looking for nanosleep - not found
Looking for sysconf
Looking for sysconf - not found
Looking for sysctlbyname
Looking for sysctlbyname - not found
Looking for getauxval
Looking for getauxval - not found
Looking for poll
Looking for poll - not found
Looking for _Exit
Looking for _Exit - found
Looking for pow in m
Looking for pow in m - found
Looking for atan
Looking for atan - found
Looking for atan2
Looking for atan2 - found
Looking for ceil
Looking for ceil - found
Looking for copysign
Looking for copysign - found
Looking for cos
Looking for cos - found
Looking for cosf
Looking for cosf - found
Looking for fabs
Looking for fabs - found
Looking for floor
Looking for floor - found
Looking for log
Looking for log - found
Looking for pow
Looking for pow - found
Looking for scalbn
Looking for scalbn - found
Looking for sin
Looking for sin - found
Looking for sinf
Looking for sinf - found
Looking for sqrt
Looking for sqrt - found
Looking for sqrtf
Looking for sqrtf - found
Looking for tan
Looking for tan - found
Looking for tanf
Looking for tanf - found
Looking for acos
Looking for acos - found
Looking for asin
Looking for asin - found
Looking for iconv_open in iconv
Looking for iconv_open in iconv - not found
Looking for alloca.h
Looking for alloca.h - not found
Performing Test HAVE_SA_SIGACTION
Performing Test HAVE_SA_SIGACTION - Failed
Looking for windows.h
Looking for windows.h - found
Looking for mmdeviceapi.h
Looking for mmdeviceapi.h - found
Looking for audioclient.h
Looking for audioclient.h - found
Looking for endpointvolume.h
Looking for endpointvolume.h - found

SDL2 was configured with the following options:

Platform: Windows-10.0.18362
64-bit: FALSE
Compiler: C:/Program Files (x86)/mingw-w64/i686-8.1.0-win32-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe

Subsystems:
Atomic: ON
Audio: ON
Video: ON
Render: OFF
Events: ON
Joystick: ON
Haptic: ON
Power: ON
Threads: ON
Timers: ON
File: ON
Loadso: ON
CPUinfo: ON
Filesystem: ON
Dlopen: OFF
Sensor: ON

Options:
ALSA (Wanted: OFF): OFF
ALSA_SHARED (Wanted: OFF): OFF
ARTS (Wanted: OFF): OFF
ARTS_SHARED (Wanted: OFF): OFF
ASSEMBLY (Wanted: ON): ON
ASSERTIONS (Wanted: auto): auto
BACKGROUNDING_SIGNAL (Wanted: OFF): OFF
CLOCK_GETTIME (Wanted: OFF): OFF
DIRECTFB_SHARED (Wanted: OFF): OFF
DIRECTX (Wanted: ON): ON
DISKAUDIO (Wanted: ON): ON
DUMMYAUDIO (Wanted: ON): ON
ESD (Wanted: OFF): OFF
ESD_SHARED (Wanted: OFF): OFF
FOREGROUNDING_SIGNAL (Wanted: OFF): OFF
FUSIONSOUND (Wanted: OFF): OFF
FUSIONSOUND_SHARED (Wanted: OFF): OFF
GCC_ATOMICS (Wanted: ON): ON
HIDAPI (Wanted: ON): ON
INPUT_TSLIB (Wanted: OFF): OFF
JACK (Wanted: OFF): OFF
JACK_SHARED (Wanted: OFF): OFF
KMSDRM_SHARED (Wanted: OFF): OFF
LIBC (Wanted: ON): ON
LIBSAMPLERATE (Wanted: OFF): OFF
LIBSAMPLERATE_SHARED (Wanted: OFF): OFF
NAS (Wanted: OFF): OFF
NAS_SHARED (Wanted: OFF): OFF
OSS (Wanted: OFF): OFF
PTHREADS (Wanted: OFF): OFF
PTHREADS_SEM (Wanted: OFF): OFF
PULSEAUDIO (Wanted: OFF): OFF
PULSEAUDIO_SHARED (Wanted: OFF): OFF
SDL_DLOPEN (Wanted: OFF): OFF
SDL_HAPTIC (Wanted: ON): ON
SDL_STATIC_PIC (Wanted: OFF): OFF
SNDIO (Wanted: OFF): OFF
VIDEO_COCOA (Wanted: OFF): OFF
VIDEO_DIRECTFB (Wanted: OFF): OFF
VIDEO_DUMMY (Wanted: ON): ON
VIDEO_KMSDRM (Wanted: OFF): OFF
VIDEO_OPENGL (Wanted: ON): ON
VIDEO_OPENGLES (Wanted: OFF): OFF
VIDEO_RPI (Wanted: OFF): OFF
VIDEO_VIVANTE (Wanted: OFF): OFF
VIDEO_VULKAN (Wanted: ON): ON
VIDEO_WAYLAND (Wanted: OFF): OFF
VIDEO_WAYLAND_QT_TOUCH (Wanted: OFF): OFF
VIDEO_X11 (Wanted: OFF): OFF
VIDEO_X11_XCURSOR (Wanted: OFF): OFF
VIDEO_X11_XINERAMA (Wanted: OFF): OFF
VIDEO_X11_XINPUT (Wanted: OFF): OFF
VIDEO_X11_XRANDR (Wanted: OFF): OFF
VIDEO_X11_XSCRNSAVER (Wanted: OFF): OFF
VIDEO_X11_XSHAPE (Wanted: OFF): OFF
VIDEO_X11_XVM (Wanted: OFF): OFF
WASAPI (Wanted: ON): OFF
WAYLAND_SHARED (Wanted: OFF): OFF
X11_SHARED (Wanted: OFF): OFF

CFLAGS: -mtune=generic -march=native -msse3 -static -static-libgcc -fno-keep-inline-dllexport -mstackrealign -fdiagnostics-color=auto -IC:/Users/8Observer8/Downloads/Urho3D-master/Source/ThirdParty/SDL/src/hidapi/hidapi
EXTRA_CFLAGS: -Wshadow -Wdeclaration-after-statement -Werror=declaration-after-statement -fno-strict-aliasing -Wall
EXTRA_LDFLAGS: -Wl,–no-undefined
EXTRA_LIBS: m;user32;gdi32;winmm;imm32;ole32;oleaut32;version;uuid;advapi32;setupapi;shell32;dinput8;dxerr8

Performing Test HAVE_STRUCT_TIMESPEC_TV_SEC
Performing Test HAVE_STRUCT_TIMESPEC_TV_SEC - Success
Looking for _TIMESPEC_DEFINED
Looking for _TIMESPEC_DEFINED - found
Performing Test INET_FUNCTIONS_EXISTS_1
Performing Test INET_FUNCTIONS_EXISTS_1 - Failed
Performing Test INET_FUNCTIONS_EXISTS_2
Performing Test INET_FUNCTIONS_EXISTS_2 - Failed
Performing Test SPRINTFS_FUNCTION_EXISTS
Performing Test SPRINTFS_FUNCTION_EXISTS - Success
Performing Test VSNPRINTFS_FUNCTION_EXISTS
Performing Test VSNPRINTFS_FUNCTION_EXISTS - Success
Looking for include file stdint.h
Looking for include file stdint.h - found
Performing Test IK_RESTRICT_restrict
Performing Test IK_RESTRICT_restrict - Success
Performing Test COMPILER_HAS_DEPRECATED_ATTR
Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
Found Urho3D: as CMake target
CMake Warning (dev) at C:/Program Files (x86)/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:272 (message):
The package name passed to find_package_handle_standard_args (rt) does
not match the name of the calling package (RT). This can lead to problems
in calling code that expects find_package result variables (e.g.,
_FOUND) to follow a certain pattern.
Call Stack (most recent call first):
Source/ThirdParty/Assimp/cmake-modules/FindRT.cmake:19 (find_package_handle_standard_args)
Source/ThirdParty/Assimp/code/CMakeLists.txt:854 (FIND_PACKAGE)
This warning is for project developers. Use -Wno-dev to suppress it.

Could NOT find rt (missing: RT_LIBRARY)
RT-extension not found. glTF import/export will be built without Open3DGC-compression.
Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
Configuring done

  1. I just unchecked some Assimp Importers. I pressed the “Configure” button again.
  2. I pressed the “Generate” button.
  3. I went to the “dist” folder and I run the “mingw32-make” command.
  4. Even EXE’s for examples was created successfully.
  5. I have the “include” folder and the “libUrho3d.a” library. I think it must be enough to build a simple program:
main.cpp
#include <iostream>
#include <Urho3D/Engine/Application.h>

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)

  1. I run the command:

g++ -Wall -g -std=c++11 main.cpp -I"C:\Users\8Observer8\Downloads\Urho3D-master\dist\include" -L"C:\Users\8Observer8\Downloads\Urho3D-master\dist\lib" -lUrho3D -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -lwinmm -limm32 -lversion -lws2_32 -ldbghelp -ld3dcompiler -ld3d11 -ldxgi -ldxguid -o app.exe

  1. This is the whole output:
Output C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `_tcf_2': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:37: undefined reference to `_imp___ZN6Urho3D8TypeInfoD1Ev' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `Z14RunApplicationv': E:\_Projects\C++\urho3d\hello-world-urho3d-cpp/main.cpp:17: undefined reference to `_imp___ZN6Urho3D7ContextC1Ev' E:\_Projects\C++\urho3d\hello-world-urho3d-cpp/main.cpp:17: undefined reference to `_imp___ZN6Urho3D11Application3RunEv' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `WinMain@16': E:\_Projects\C++\urho3d\hello-world-urho3d-cpp/main.cpp:17: undefined reference to `_imp___ZN6Urho3D14ParseArgumentsEPKw' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D7VariantD1Ev': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Core/Variant.h:556: undefined reference to `_imp___ZN6Urho3D7Variant7SetTypeENS_11VariantTypeE' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D11Application17GetTypeInfoStaticEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:37: undefined reference to `_imp___ZN6Urho3D8TypeInfoC1EPKcPKS0_' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D11ApplicationD2Ev': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:35: undefined reference to `_imp___ZTVN6Urho3D11ApplicationE' C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:35: undefined reference to `_imp___ZN6Urho3D6ObjectD2Ev' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D11ApplicationD1Ev': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:35: undefined reference to `_imp___ZTVN6Urho3D11ApplicationE' C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:35: undefined reference to `_imp___ZN6Urho3D6ObjectD2Ev' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN5MyAppC1EPN6Urho3D7ContextE': E:\_Projects\C++\urho3d\hello-world-urho3d-cpp/main.cpp:7: undefined reference to `_imp___ZN6Urho3D11ApplicationC2EPNS_7ContextE' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D7HashMapINS_10StringHashENS_7VariantEED1Ev': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/HashMap.h:256: undefined reference to `_imp___ZN6Urho3D21AllocatorUninitializeEPNS_14AllocatorBlockE' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D7HashMapINS_10StringHashENS_7VariantEE5ClearEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/HashMap.h:463: undefined reference to `_imp___ZN6Urho3D8HashBase9ResetPtrsEv' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D7HashMapINS_10StringHashENS_7VariantEE8FreeNodeEPNS3_4NodeE': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/HashMap.h:762: undefined reference to `_imp___ZN6Urho3D13AllocatorFreeEPNS_14AllocatorBlockEPv' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D9SharedPtrINS_6EngineEE10ReleaseRefEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/Ptr.h:237: undefined reference to `_imp___ZN6Urho3D10RefCounted10ReleaseRefEv' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D9SharedPtrINS_7ContextEE6AddRefEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/Ptr.h:229: undefined reference to `_imp___ZN6Urho3D10RefCounted6AddRefEv' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D9SharedPtrINS_7ContextEE10ReleaseRefEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/Ptr.h:237: undefined reference to `_imp___ZN6Urho3D10RefCounted10ReleaseRefEv' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D9SharedPtrI5MyAppE6AddRefEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/Ptr.h:229: undefined reference to `_imp___ZN6Urho3D10RefCounted6AddRefEv' C:\Users\8OBSER~1\AppData\Local\Temp\ccCo3yPo.o: In function `ZN6Urho3D9SharedPtrI5MyAppE10ReleaseRefEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/Ptr.h:237: undefined reference to `_imp___ZN6Urho3D10RefCounted10ReleaseRefEv' C:\Users\8Observer8\Downloads\Urho3D-master\dist\lib/libUrho3D.a(hid.c.obj):hid.c:(.text+0x3cb): undefined reference to `_imp__SetupDiGetClassDevsA@16' C:\Users\8Observer8\Downloads\Urho3D-master\dist\lib/libUrho3D.a(hid.c.obj):hid.c:(.text+0x408): undefined reference to `_imp__SetupDiEnumDeviceInterfaces@20' C:\Users\8Observer8\Downloads\Urho3D-master\dist\lib/libUrho3D.a(hid.c.obj):hid.c:(.text+0x440): undefined reference to `_imp__SetupDiGetDeviceInterfaceDetailA@24' C:\Users\8Observer8\Downloads\Urho3D-master\dist\lib/libUrho3D.a(hid.c.obj):hid.c:(.text+0x480): undefined reference to `_imp__SetupDiGetDeviceInterfaceDetailA@24' C:\Users\8Observer8\Downloads\Urho3D-master\dist\lib/libUrho3D.a(hid.c.obj):hid.c:(.text+0x4a0): undefined reference to `_imp__SetupDiEnumDeviceInfo@12' C:\Users\8Observer8\Downloads\Urho3D-master\dist\lib/libUrho3D.a(hid.c.obj):hid.c:(.text+0x4c7): undefined reference to `_imp__SetupDiGetDeviceRegistryPropertyA@28' C:\Users\8Observer8\Downloads\Urho3D-master\dist\lib/libUrho3D.a(hid.c.obj):hid.c:(.text+0x525): undefined reference to `_imp__SetupDiDestroyDeviceInfoList@4' collect2.exe: error: ld returned 1 exit status

For example, I use a similar command for building apps with the SFML library. This command works correctly:

g++ main.cpp -I"E:\Libs\SFML\SFML-2.5.1-windows-gcc-7.3.0-mingw-32-bit\SFML-2.5.1\include" -L"E:\Libs\SFML\SFML-2.5.1-windows-gcc-7.3.0-mingw-32-bit\SFML-2.5.1\lib" -lsfml-graphics -lsfml-window -lsfml-system -o hero.exe

Maybe do I use incorrect keys? Where can I find correct keys?

This problem was solved using this key: -lSetupapi

But what key will solve this problem:

C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:37: undefined reference to `_imp___ZN6Urho3D8TypeInfoD1Ev’

This command:

g++ -Wall -g -std=c++11 main.cpp -I"C:\Users\8Observer8\Downloads\Urho3D-master\dist\include" -L"C:\Users\8Observer8\Downloads\Urho3D-master\dist\lib" -lUrho3D -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -lwinmm -limm32 -lversion -lws2_32 -ldbghelp -ld3dcompiler -ld3d11 -ldxgi -ldxguid -lSetupapi -o app.exe

gives me these errors:

C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function_tcf_2’:
C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:37: undefined reference to _imp___ZN6Urho3D8TypeInfoD1Ev' C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function Z14RunApplicationv’:
E:_Projects\C++\urho3d\hello-world-urho3d-cpp/main.cpp:18: undefined reference to _imp___ZN6Urho3D7ContextC1Ev' E:\_Projects\C++\urho3d\hello-world-urho3d-cpp/main.cpp:18: undefined reference to _imp___ZN6Urho3D11Application3RunEv’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function WinMain@16': E:\_Projects\C++\urho3d\hello-world-urho3d-cpp/main.cpp:18: undefined reference to _imp___ZN6Urho3D14ParseArgumentsEPKw’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D7VariantD1Ev': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Core/Variant.h:556: undefined reference to _imp___ZN6Urho3D7Variant7SetTypeENS_11VariantTypeE’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D11Application17GetTypeInfoStaticEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:37: undefined reference to imp___ZN6Urho3D8TypeInfoC1EPKcPKS0
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D11ApplicationD2Ev': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:35: undefined reference to _imp___ZTVN6Urho3D11ApplicationE’
C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:35: undefined reference to _imp___ZN6Urho3D6ObjectD2Ev' C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D11ApplicationD1Ev’:
C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:35: undefined reference to _imp___ZTVN6Urho3D11ApplicationE' C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Engine/Application.h:35: undefined reference to _imp___ZN6Urho3D6ObjectD2Ev’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN5MyAppC1EPN6Urho3D7ContextE': E:\_Projects\C++\urho3d\hello-world-urho3d-cpp/main.cpp:8: undefined reference to _imp___ZN6Urho3D11ApplicationC2EPNS_7ContextE’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D7HashMapINS_10StringHashENS_7VariantEED1Ev': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/HashMap.h:256: undefined reference to _imp___ZN6Urho3D21AllocatorUninitializeEPNS_14AllocatorBlockE’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D7HashMapINS_10StringHashENS_7VariantEE5ClearEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/HashMap.h:463: undefined reference to _imp___ZN6Urho3D8HashBase9ResetPtrsEv’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D7HashMapINS_10StringHashENS_7VariantEE8FreeNodeEPNS3_4NodeE': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/HashMap.h:762: undefined reference to _imp___ZN6Urho3D13AllocatorFreeEPNS_14AllocatorBlockEPv’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D9SharedPtrINS_6EngineEE10ReleaseRefEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/Ptr.h:237: undefined reference to _imp___ZN6Urho3D10RefCounted10ReleaseRefEv’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D9SharedPtrINS_7ContextEE6AddRefEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/Ptr.h:229: undefined reference to _imp___ZN6Urho3D10RefCounted6AddRefEv’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D9SharedPtrINS_7ContextEE10ReleaseRefEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/Ptr.h:237: undefined reference to _imp___ZN6Urho3D10RefCounted10ReleaseRefEv’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D9SharedPtrI5MyAppE6AddRefEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/Ptr.h:229: undefined reference to _imp___ZN6Urho3D10RefCounted6AddRefEv’
C:\Users\8OBSER~1\AppData\Local\Temp\ccirz7RL.o: In function ZN6Urho3D9SharedPtrI5MyAppE10ReleaseRefEv': C:/Users/8Observer8/Downloads/Urho3D-master/dist/include/Urho3D/Container/Ptr.h:237: undefined reference to _imp___ZN6Urho3D10RefCounted10ReleaseRefEv’
collect2.exe: error: ld returned 1 exit status
`

Looks like it can’t find the libUrho3D.a, are you sure you’re linking to the correct folder?

1 Like

When I break the path:

g++ -Wall -g -std=c++11 main.cpp -I"C:\Users\8Observer8\Downloads\Urho3D-master\dist\include" -L"C:\Users\8Observer8\Downloads\Urho3D-master\dist" -lUrho3D -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32
-lole32 -loleaut32 -luuid -lcomdlg32 -lSetupapi -ladvapi32 -lwinmm -limm32 -lversion -lws2_32 -ldbghelp -lopengl32 -o app.exe

I get this:

C:/Program Files (x86)/mingw-w64/i686-8.1.0-win32-dwarf-rt_v6-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lUrho3D collect2.exe: error: ld returned 1 exit status

As I suggested before, run the make command verbosely and see the actual commands used to compile something, let’s say one of the samples. I think you’re missing some of the flags, but I can’t tell you just from looking at then which will be needed.

From your CMake output:

CFLAGS: -mtune=generic -march=native -msse3 -static -static-libgcc -fno-keep-inline-dllexport -mstackrealign -fdiagnostics-color=auto -IC:/Users/8Observer8/Downloads/Urho3D-master/Source/ThirdParty/SDL/src/hidapi/hidapi
EXTRA_CFLAGS: -Wshadow -Wdeclaration-after-statement -Werror=declaration-after-statement -fno-strict-aliasing -Wall
EXTRA_LDFLAGS: -Wl,–no-undefined
EXTRA_LIBS: m;user32;gdi32;winmm;imm32;ole32;oleaut32;version;uuid;advapi32;setupapi;shell32;dinput8;dxerr8
1 Like

I did not understand you before. Now I understand that I need to run the next command and I will try it later:

mingw32-make VERBOSE=1

The build command above works with “shared” version of Urho. I downloaded Urho3D-1.7.1-MinGW-SHARED. When I run the command:

g++ -Wall -g -std=c++11 main.cpp -I"C:\Users\8Observer8\Downloads\Urho3D-1.7.1-MinGW-SHARED\include" -L"C:\Users\8Observer8\Downloads\Urho3D-1.7.1-MinGW-SHARED\lib\Urho3D" -lUrho3D -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -lSetupapi -ladvapi32 -lwinmm -limm32 -lversion -lws2_32 -ldbghelp -lopengl32 -o app.exe

I get “app.exe”. But I get this warning after compilation:

Output ` In file included from C:/Users/8Observer8/Downloads/Urho3D-1.7.1-MinGW-SHARED/include/Urho3D/Core/Attribute.h:26, from C:/Users/8Observer8/Downloads/Urho3D-1.7.1-MinGW-SHARED/include/Urho3D/Core/Context.h:26, from C:\Users\8Observer8\Downloads\Urho3D-1.7.1-MinGW-SHARED\include/Urho3D/Engine/Application.h:25, from main.cpp:2: C:/Users/8Observer8/Downloads/Urho3D-1.7.1-MinGW-SHARED/include/Urho3D/Core/Variant.h: In member function 'bool Urho3D::Variant::operator==(long long unsigned int) const': C:/Users/8Observer8/Downloads/Urho3D-1.7.1-MinGW-SHARED/include/Urho3D/Core/Variant.h:734:141: warning: comparison of integer expressions of different signedness: 'const long long unsigned int' and 'int' [-Wsign-compare] bool operator ==(unsigned long long rhs) const { return type_ == VAR_INT64 ? *reinterpret_cast(&value_.int_) == (int)rhs : false; } `

I copied the “Urho3D.dll” from the folder:

  • C:\Users\8Observer8\Downloads\Urho3D-1.7.1-MinGW-SHARED\bin

to

  • C:\Windows\SysWOW64

I run “app.exe” and It works! I read here that I need to add “Data” and “CoreDate”.

main.cpp
// #include <Urho3D/Urho3D.h>
#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)
Output
  • Setup
  • [Sun May 03 02:10:36 2020] INFO: Opened log file Urho3D.log
  • [Sun May 03 02:10:36 2020] INFO: Created 1 worker thread
  • [Sun May 03 02:10:36 2020] INFO: Added resource path E:/_Projects/C++/urho3d/hello-world-urho3d-cpp/Data/ [Sun May 03 02:10:36 2020] INFO: Added resource path E:/_Projects/C++/urho3d/hello-world-urho3d-cpp/CoreData/
  • [Sun May 03 02:10:43 2020] INFO: Set screen mode 1366x768 fullscreen monitor 0
  • [Sun May 03 02:10:43 2020] INFO: Initialized input
  • [Sun May 03 02:10:43 2020] INFO: Initialized user interface
  • [Sun May 03 02:10:43 2020] ERROR: Could not find resource Textures/Ramp.png
  • [Sun May 03 02:10:43 2020] ERROR: Could not find resource Textures/Spot.png
  • [Sun May 03 02:10:43 2020] ERROR: Could not find resource Techniques/NoTexture.xml
  • [Sun May 03 02:10:43 2020] ERROR: Could not find resource RenderPaths/Forward.xml
  • [Sun May 03 02:10:43 2020] INFO: Initialized renderer
  • [Sun May 03 02:10:43 2020] INFO: Set audio mode 44100 Hz stereo interpolated
  • [Sun May 03 02:10:43 2020] INFO: Initialized engine

It is time to study and practice with Urho. I will try to compile statically an example later. Thank you, guys!

1 Like

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