MainDocs:Visual C++ on Windows

From ClanLib Game SDK

Contents

Getting started

First step is to make sure your Visual Studio system is up to date. As of this writing, we support the following versions:


You also need to install a version of the DirectX SDK, but there is no need for the very latest. So if you already have a version installed that will work just fine.

Precompiled libraries or compile ClanLib ?

If you need the very latest Clanlib directly from our source control repository, read the compilation guide instead.

Otherwise and much easier, you can just use the precompiled versions we provide, these are always up-to-date on the latest release. Read on for a guide on using the precompiled libraries.

Downloading precompiled libraries

Download the ClanLib and the Dependency libraries: Visual Studio binaries

After you downloaded the binaries, exctract these files into a directory. Remember which one, because you need to enter that information in the next section. It will create a structure looking like this:

Configure Visual Studio

You will need to configure Visual Studio to look for the downloaded libraries.

Adding global includes to Visual Studio 2008

Adding global includes to Visual Studio 2010

Creating a solution for your application

Follow these steps to create a Visual Studio solution for a ClanLib application:

  1. Select File->New Project.

  2. Find Visual C++ group in the Project Types, and select Win32 Project, and specify the location, and click OK.
    File:visualstudio_new_project.png

  3. Under Application Settings, select Empty project , and press Finish.
    File:visualstudio_new_project_settings.png

  4. Add a new C++ file to your project. This can be done by right clicking your project in Solution Explorer, and selecting Add->New Item->C++ File.
    (If you do not do this first, you will not see the C++ / Code Generation settings required for step 7).

  5. Right click your Project (not the solution) and select Properties.

  6. Select the Configuration Properties section.

  7. Select the C/C++ tab, and then Category Code Generation.

  8. Change the Use run-time library to Debug Multithreaded.File:visualstudio_runtime_library_debug.png

  9. Change the configuration dropdown at the top of the dialog to Release.

  10. Change the Use run-time library to Multithreaded.File:visualstudio_runtime_library_release.png

Examples

That should be it. If you've done everything correct, you can start coding your ClanLib application!

You could also check out the examples that comes with the distribution; they are a great resource to learn from. Since the precompiled packages does not include the examples, you will need to download the ClanLib source package. Download the ClanLib source package, extract it anywhere, and open the Examples.sln Visual Studio solution file.

Problems?

The most common problems encountered with building ClanLib applications:

1. Problem: You get a lot of linker errors complaining about multiple definitions of functions like _exit or an error "cannot open file '*-static-mtdll-debug.lib' "

This is almost always caused by mixing runtime versions. Your project is most likely set to Multithreaded Debug DLL, while ClanLib expects it to be Multithreaded Debug. Fixed by going to the project settings of your project and set it to what ClanLib expects.

2. Problem: You get a lot of linker errors complaining about xran and similar.

This is probably caused by using libraries compiled with Visual Studio 2008 in a Visual Studio 2010 environment. Download the correct precompiled versions.

3. Problem: LINK : fatal error LNK1104: cannot open file 'zlib-static-mt-debug.lib'

Visual Studio cannot locate the ClanLib dependency libraries. Make sure you have setup the include and libs directories correctly as explained in the guide. If you only have files like zlib-x64-static-mt-debug.lib, make sure you compile your application in 64 bit and not 32 bit.