How to use urho3d with an existing project

I have an existing project with some libraries,I coding in Ubuntu, and using CMake to build my program. Now I want to add urho3d as an external library to add 3D feature for my project, but I dont know how to config my CMakeLists file to make urho3d work with my project.
This is what I did:

  • complied and installed Urho3d into my system. (I follow the tutorial in wiki page “Setting-up-a-Project-(CMake)” and it worked so I am sure Urho3d is working now on my pc)
  • Copy CMake folder in Urho3D folder into my project folder.
  • Create a bin folder with a CoreData and a Data folder inside in my project directory.
  • add the following line into my CMakeLists.txt file
# Set CMake modules search path
# Include Urho3D Cmake common module
include (Urho3D-CMake-common)

cmake run with no problem but it had error when I try to “make” a test3D.cpp file

Test3D.cpp:(.text.startup+0x1f): undefined reference to `Urho3D::EventNameRegistrar::RegisterEventName(char const*)'
Test3D.cpp:(.text.startup+0x2e): undefined reference to `Urho3D::StringHash::StringHash(char const*)'
Test3D.cpp:(.text.startup+0x3d): undefined reference to `Urho3D::StringHash::StringHash(char const*)'
Test3D.cpp:(.text.startup+0x4c): undefined reference to `Urho3D::EventNameRegistrar::RegisterEventName(char const*)'
Test3D.cpp:(.text.startup+0x5b): undefined reference to `Urho3D::StringHash::StringHash(char const*)'
Test3D.cpp:(.text.startup+0x6a): undefined reference to `Urho3D::EventNameRegistrar::RegisterEventName(char const*)'
Test3D.cpp:(.text.startup+0x79): undefined reference to `Urho3D::StringHash::StringHash(char const*)'
Test3D.cpp:(.text.startup+0x88): undefined reference to `Urho3D::EventNameRegistrar::RegisterEventName(char const*)'
Test3D.cpp:(.text.startup+0x97): undefined reference to `Urho3D::StringHash::StringHash(char const*)'
Test3D.cpp:(.text.startup+0xa6): undefined reference to `Urho3D::EventNameRegistrar::RegisterEventName(char const*)'
Test3D.cpp:(.text.startup+0xb5): undefined reference to `Urho3D::StringHash::StringHash(char const*)'
Test3D.cpp:(.text.startup+0xc4): undefined reference to `Urho3D::EventNameRegistrar::RegisterEventName(char const*)'
collect2: error: ld returned 1 exit status

my test3d.cpp file

// my first program in C++
#include <string>
#include <sstream>

#include <Urho3D/Core/CoreEvents.h>

// using namespace Urho3D;

int test(int argc, char **argv)
  printf("hehehehehe\n" );
  return 0;

Sorry if this is a stupid question, I am new both with urho3d and CMake.
Thank you.

Have you read an article at about using urho3d with an existing project?

yes, I follow the tutorial in wiki page “Setting-up-a-Project-(CMake)” and it worked so I am sure Urho3d is working now on my pc.

Here’s my current setup. I’m using CLion and MinGW64 6.2 (posix) as the compiler. Disclaimer: I’m no CMake expert so there may be problems…

This setup is useful if you’re compiling your game as a DLL and you’ve created a launcher.exe to launch your game or custom editor, which is what I’m doing. However, I think it’s useful to know how to separate out your CMake stuff with Urho’s methods.

# Set the URHO3D_HOME variable manually

# Append my game includes with the URHO3D includes

# Include whatever files you want to use throughout your project
# ...

# Set the include directories.

# Include Urho3D Cmake common module
include (Urho3D-CMake-common)

# Find Urho3D library
find_package (Urho3D REQUIRED)

# Add the Urho3D Library (based on debug/release mode)
add_library(Urho3DLib STATIC IMPORTED)
    set_property(TARGET Urho3DLib PROPERTY IMPORTED_LOCATION ${URHO3DSDK_HOME}/lib/libUrho3D_d.a)
else ()
    set_property(TARGET Urho3DLib PROPERTY IMPORTED_LOCATION ${URHO3DSDK_HOME}/lib/libUrho3D.a)
endif ()

In my case, I’m forced to used static linking, because if you’re doing a Game.dll file, CMake (or I haven’t found out at least), doesn’t allow a target dll to import another dll… which is sad/annoying. :frowning:
Now, when building your exe, you can do the following:


# Header and src files.


# For Mac support I do the following... (I've had to do this after updating to the latest xcode version)
list (APPEND AppleLibs "")
if (APPLE)
    list (APPEND AppleLibs "-framework AudioToolbox" "-framework CoreAudio" "-framework CoreGraphics" "-framework Foundation" "-framework GameController" "-framework QuartzCore")
endif ()

add_executable(MyGame ${MYGAME_HEADERS} ${MYGAME_SOURCES})

# Now add our dependencies.
define_dependency_libs (Urho3D)

The ABSOLUTE_PATH_LIBS and LIBS come from Urho3D. You’ll want to include them so you don’t run into any undefined errors when building statically/dynamically.

This is a bit of a drawn out setup the way I have it, but it allows me a bit more flexibility with other libs. I just started working with wxWidgets, which I link as a dll, and it works with Urho perfectly. I hope this helps and good luck!