[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 4.21.4 Creating an External Crystal Space Application Using Dev-CPP

This section describes how you can use Dev-CPP to compile external applications using Crystal Space and CEL. Crystal Space does not presently have project files for Dev-CPP so, at this time, you will need to use MinGW and MSYS to build Crystal Space itself, however, for your own external applications, you can use Dev-CPP.

#### External Application Requirements

First, configure, build, and install Crystal Space (and optionally CEL) using MinGW and MSYS.

If you installed Crystal Space in a non-standard location you probably will need to set the ``CRYSTAL'` environment variable to point at the the location where the SDK was installed. For instance, if you specified ``--prefix=/site/sdk'` when configuring Crystal Space, then you will need to set ``CRYSTAL'` to ``/site/sdk'`.

If you plan to use CEL then you also must set the ``CEL'` environment variable.

#### Specifying the Compiler

Chances are, the compiler which is provided by Dev-CPP is not compatible with the built Crystal Space since Crystal Space is compiled using the version of MingW which you have installed. The easiest way to avoid problems with compiler versions here is to define a new compiler in Dev-CPP. To do so, invoke the Tools/Compiler Options menu item and click on the green ``+'` icon to add a compiler called MinGW. Make sure that that compiler is active in the popup and then switch to the Directories tab. On that tab change the path of everything to point to your MinGW installation rather than the Dev-CPP versions. In the Binaries sub-tab you have to add both the ``bin'` directory of MinGW, as well as the the ``bin'` directory of MSYS (and remove the path to Dev-CPP). In the Libraries sub-tab add the path to the MinGW ``lib'` directory, and do the same for the C Includes sub-tab. In the C++ Includes tab you have to add the correct ``C++'` MinGW ``include'` directory. If this is done correctly you should now be able to use the compiler from MinGW.

#### Creating a New Project

Select the ``File/New/Project'` menu and choose ``Console Application'` as the project type. Select an appropriate name and make sure ``C++'` is selected as the language. Save the project file in an appropriate directory. It is best to make a new directory for the project file and all other files related to the project.

If this is done succesfully Dev-CPP will open with an unsaved ``main.cpp'`. Don't save it yet.

#### Project Settings

First, you need to prepare various settings in the project. Select the Project/Project Options menu. Navigate to the Compiler tab and switch to the new MinGW compiler which you defined earlier. Next, go to the Parameters tab where you need to add the Crystal Space (and optionally CEL) libraries with which you want to link. For Crystal Space, assuming that no special ``--prefix'` was used, the libraries will usually be in ``c:\msys\1.0\local\lib'` if MSYS was installed in ``c:\msys'`, adjust the path(s) as necessary. If not, then you can access the directories from the build location with a path that looks somewhat like this: ``..\CS\out\msysx86\optimize\libs'`. Substitute ``debug'` for ``optimize'` if you build the project in debug mode.

If you installed the Crystal Space SDK, add the following libraries:

    ..\CS\lib\libcrystalspace.a

If you did not install the SDK, then add the directories from the build directory (subtituting ``debug'` for ``optimize'` if you build in debug mode):

    ..\CS\out\msysx86\optimize\libs\libcrystalspace.a

Finally, you have to add the GDI library. This can be found in the MinGW directory. For example:

    ..\MinGW-3.1.0-1\lib\libgdi32.a

Next, proceed to the Directories tab. In that tab switch to the Include Directories sub-tab and add the following:

    ..\CS\include\crystalspace
    ..\CS\include
    src
    ..\cel\include

The last one should only be added if you plan to use CEL.

The ``src'` directory is where you will put all source code for your project. (This is optional, of course.)

This concludes the project settings.

#### Additional Dynamic Link Libraries

Crystal Space requires a few Dynamic Link Libraries (DLL's) so that the program can run. The DLL's that are required depend on what your application needs but they can be any of the DLL's which you find in your path where you installed the Crystal Space Library package for Windows (the ``cs-win32libs'` package). Most commonly the following are at least required:

You can either copy those dll's manually to the project folder (the place where the executable will reside), or you can make sure the DLL's are in a standard location mentioned by your ``PATH'` environment variable, or where DLL's are typically found (e.g. inside the ``c:\windows'` folder, for instance, though modification of system folders is deprecated and discouraged).

#### Getting Started

Now that the project is set up it is time to start programming. As an example, replace the ``main.cpp'` with the one provided here:

    #include <crystalspace.h>
    #include "myapp.h"

    CS_IMPLEMENT_APPLICATION

    int main(int argc, char *argv[])
    {
      MyApp app;
      return app.Main (argc, argv);
    }

After this, create ``myapp.h'` and ``myapp.cpp'`, which will define the master `MyApp` class for the application. Refer to the other tutorials in this manual for more information on how to proceed from this point. See section Simple Tutorial 1.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ]

This document was generated using texi2html 1.76.