Skip to content

Compiling Urho3D on Windows with CodeBlocks

魔大农 edited this page Aug 14, 2019 · 1 revision

This is a quickstart and step by step version of http://urho3d.github.io/documentation/1.6/_building.html.
Sometimes there are alternative methods to do something, those are marked with
"Option 1: ... Option 2: ...".

Urho 1.6 did not work on MinGW (https://github.com/urho3d/Urho3D/issues/1552) so you will need a later version.
This guide used Urho Git version 13ed7bbbb6f4e0d1e7db6b13223835b86b582757:
https://github.com/urho3d/Urho3D/tree/13ed7bbbb6f4e0d1e7db6b13223835b86b582757
Other software versions used when making this guide were: CMake 3.6.2, Code::Blocks 16.01 and MinGW64 6.2.0 on a Windows 10 64bit.

1. Get the Urho3D Source

Option 1: Get the latest stable (not 1.6 if you are using MinGW) or one of the snapshots from https://sourceforge.net/projects/urho3d/files/Urho3D/.

Option 2: Get the newest source code as a ZIP from https://github.com/urho3d/Urho3D
or directly via Git from https://github.com/urho3d/Urho3D.git.

2. CMake

Get and install CMake: https://cmake.org/download/

3. MinGW

Get and install MinGW: https://sourceforge.net/projects/mingw-w64/files/latest/download
(The project website is https://mingw-w64.org/)
This MinGW from the MinGW64 project works usually better and is easier to use than the one from the "normal" MinGW project.

If you want to build 64bit software you have to switch the architecture to x86_64 like I did here. If you want 32bit you can leave the default of i686.

4. Code::Blocks

Direct link to current newest stable version: https://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/codeblocks-16.01-setup.exe/download
(The project website is http://www.codeblocks.org/)

There's also a Code::Blocks version bundled with a MinGW but that MinGW is usually an outdated 32bit MinGW from the "normal" MinGW-Project and not from the better MinGW-64-Project. You could also try the MinGW bundled with Code::Blocks but it might not work.

Code::Blocks may be unable to find MinGW so it has to be set up manually:

Start Code::Blocks and go to Settings->Compiler->"Toolchain executables".
Select your MinGW installation path and change the names for the "C compiler" and the "C++ compiler" to just gcc.exe and g++.exe (they are preceded by "mingw" by default). Save the settings with Ok and quit Code::Blocks.

5. Change your PATH variable

CMake needs this to find MinGW.

  1. Open an explorer window and right click on "This PC".
  2. -> Properties
  3. -> Advanced System Settings
  4. -> Environment Variables
  5. Select "Path" and either press edit or double click on it
  6. Copy the path to where you installed MinGW. You need the /bin subdirectory. (you can click in and copy from the marked address bar)
  7. Enter a ; and paste the path. (Entries in this list are seperated by semicolons.)
  8. Click Ok everywhere.

6. Build

Extract Urho3D if it's in an archive.

You could either use CMake manually, or use the CMake GUI, or just use the scripts shipped with Urho:

  1. Go to where you have unpacked Urho
  2. Click "File"->"Open command prompt" or press Shift+right click somewhere in the folder or Shift+F10 to open a menu with the "Open command window here" option. This opens a terminal.
  3. Start the "cmake_codeblocks.bat" script with a folder name as a parameter (doesn't have to exist) where you want to create the project files.

You can also set build options for Urho when executing the script like in the image, for example:

cmake_codeblocks.bat Build -DURHO3D_OPENGL=0 -DURHO3D_WIN32_CONSOLE=1

This builds Urho with DirectX9 instead of OpenGL (default) and with the console option (displays logging in a terminal when using the samples). See http://urho3d.github.io/documentation/1.6/_building.html for all options.

7. Open the Urho3D project files and build.

Go to the build folder, open the Code::Blocks project and build Urho3D:

This can take a while (here 24 minutes).

When it is done you can go to the bin folder and check out the samples:

8. Create a new system variable "URHO3D_HOME"

If you want to use Urho3D in a project with the normal scripts, you have to create a new system variable that points to your build Urho:

This is quite similar to step 4.

You can continue with creating your first project that uses Urh3D: [Setting up an Urho3D Project (CMake)](Setting up a Project (CMake))