Difference between revisions of "SDL"

From NikiWiki
Jump to: navigation, search
(Using the GNU C Compiler)
(Using the GNU C Compiler)
Line 64: Line 64:
 
  emximp -o sdl.imp sdl.lib
 
  emximp -o sdl.imp sdl.lib
 
  emximp -o sdl.a sdl.imp
 
  emximp -o sdl.a sdl.imp
 +
 +
If you plan on using SDL's multithreading capabilities (e.g. if you want
 +
to include "SDL_thread.h"), be sure that enable multithreading with -Zmt
 +
on your GCC commandline, otherwise you'll get an error because _beginthread()
 +
and _endthread() will not be defined.
  
 
=== General tips and tricks ===
 
=== General tips and tricks ===

Revision as of 22:36, 29 August 2004

Porting SDL applications to OS/2

Requirements

To port SDL applications to OS/2, you'll need the latest SDL binaries and header files from netlabs.org. Currently the OpenWatcom compiler is the compiler for the OS/2 port of SDL, but it should also work with GCC.

Using the OpenWatcom compiler

There are some requirements and tricks with using the OpenWatcom compiler to port SDL applications. You should note the followings things.

Use the -ei switch for the OpenWatcom C compiler

You have to use the -ei switch for the OpenWatcom C compiler to have the size of enums equal to the size of ints. This is a requirement of SDL itself.

Wrapping the SDL_Quit() function

The OS/2 version of SDL is compiled into a DLL file. This DLL file has all the SDL functions exported by name. In order to be able to use this DLL from most of the available compilers, these exports are using the _Syscall calling convention. This leads to problems with some SDL apps, where they assume that the calling convention of the API is the same as the calling convention of their runtime library. For example, the following line is very usual in SDL applications:

...
atexit(SDL_Quit);
...

This should be worked around by creating a wrapper function for SDL_Quit, and using that one, this way:

#ifdef __WATCOMC__
void SDL_Quit_Wrapper()
{
   SDL_Quit();
}
#endif
...
#ifdef __WATCOMC__
atexit(SDL_Quit_Wrapper);
#else
atexit(SDL_Quit);
#endif;

Using the GNU C Compiler

It was reported that some (or maybe all) of the GNU C compilers (GCC) available for OS/2 can not handle the SDL.LIB file included in the SDL DevPack. The problem is that the SDL.LIB file was created directly from the SDL.DLL file, using the IMPLIB.EXE tool from the OS/2 Developer's Toolkit, and the GCC does not recognize it to be a valid library file.

There is a workaround, which is reported to work in this case. One has to create a GCC-compatible library file (.a), using the EMXIMP tool, and link against that file:

emximp -o sdl.imp sdl.lib
emximp -o sdl.a sdl.imp

If you plan on using SDL's multithreading capabilities (e.g. if you want to include "SDL_thread.h"), be sure that enable multithreading with -Zmt on your GCC commandline, otherwise you'll get an error because _beginthread() and _endthread() will not be defined.

General tips and tricks

Morph your program to a PM program at runtime

Most SDL applications assume that they can write to STDOUT, and the user will see it. In OS/2, you have to compile your application to a PM application in order to be able to have a PM Window, but the STDOUT will go to NULL in this case. The solution is to compile your code to a VIO application, and morph the application to a PM one dynamically, at runtime, before calling SDL_Init().