Watcom, GLUT and SDL


Abstract

This document gives some advices to everyone who is trying to use SDL and GLUT with the Watcom compiler. This document does not pretent do be the a full and exhaustive guide to make Watcom work with GLUT and SDL, its primary purpose is to show how the author made them work together.

Introduction

There are a lot of non-programming related issues about the use of a Watcom compiler wit GLUT or SDL libraries.

The author is not a Watcom power-user but recently installed Watcom compiler on a Windows machine and wanted to port/compile some of his OpenGL/SDL application on that system.

Here we show some raw solutions: probably thre are better solutions but the aouthor is not aware of them.

These solutions come from web sites, news group posts and official Watcom manuals. Other infos can be found in SDL and GLUT readme-files files.

We provide compiler/linker options for both wcc386 and owcc.

wcc386 is the Watcom C/C++ compiler for Win32 platform.

owcc is the POSIX compliant Watcom C/C++ compiler for Win32 platform.

In all the tutorial we use some conventions:

GLUT

GLUT library for Windows can be found on web at this address.

After the download GLUT must be installed in the following way:

To use GLUT we must include GLUT header file in the following way:

#include <GL/glut.h>

Caveat: stdlib.h must be included before glut.h or Watcom will output something like the following:

Open Watcom C32 Optimizing Compiler Version 1.5
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
C:\WATCOM\H\stdlib.h(210): Error! E1057: Modifiers disagree with previous definition of 'exit'
C:\WATCOM\H\stdlib.h(210): Note! N2002: 'exit' defined in: C:\WATCOM\H\NT\GL/glut.h(146)
...

wcc386

With wcc386 function arguments must be passed on the stack (option /5s)

Files must be first compiled...

wcc386 /5s file.c

...and then linked to produce an executable file:

wlink option quiet name file.exe file file.obj

owcc

With owcc function arguments are passed on the stack. But there is another problem. GLUT as an hack for the atexit function. This hack must be disabled. One way is from source code. Before the include of glut.h code must report the following line:

#define GLUT_DISABLE_ATEXIT_HACK

The hack can be disabled also from the command line of the compiler. On the compiler line we must also include the library files to be linked with the executable:

owcc -DGLUT_DISABLE_ATEXIT_HACK -o file.exe file.c opengl32.lib glut32.lib glu32.lib

SDL

SDL can be downloaded on web at this address (the version to download is the development library for Win32 (Visual C++ 5,6,7).

After the download SDL must be installed in the following way:

To use SDL we must include SDL and OpenGL header files in the following way:

#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>

wcc386

With wcc386 function arguments must be passed on the stack (option /5s) and enums must be threated as integers (/ei). To enable the equivalence between enums and integeres it is possible to use a pragma instead of the command line switch

#pragma enum int

Another issue with SDL library is that it defines it's own main (using a macro). This feature does produce errors with Watcom compiler. To address this problem this feature must be undef. The code must contain the following line.

#define SDL_main main

It is also possible to do this on command line with /d switch.

wcc386 file.c /dSDL_main=main /5s /ei

To use SDL we must also include the reference to libraries that must be linked.

#pragma library ("SDL.lib")
#pragma library ("SDLmain.lib")
#pragma library ("opengl32.lib")
#pragma library ("glu32.lib")

To build the application we need to compile...

wcc386 file.c /5s /ei

...and then link to produce the executable:

wlink option quiet name file.exe file file.obj

Without using pragmas for library files it is also possible to tell to the linker what libraries must be linked

wlink option quiet name file.exe file file.obj library SDL.lib,SDLmain.lib,opengl32.lib,glu32.lib

owcc

owcc compiler does not provide flags to specify the equivalence between enum and integers for this reason source code must contain the following line

#pragma enum int

To address the problem given by main redefinition the following line must be specified

#define SDL_main main

It is also possible to use the compiler switch -D to have the same compiler behaviour (the following code produce the object file, not the executable)

owcc -DSDL_main=main -c file.c

To use SDL we must also include the reference to libraries that must be linked

#pragma library ("SDL.lib")
#pragma library ("SDLmain.lib")
#pragma library ("opengl32.lib")
#pragma library ("glu32.lib")

In this way to compile an application the command line is the following

owcc -o file.exe file.c

It is also possible to specify libraries on the command line as for standard object files

owcc -o file.exe file.c SDL.lib SDLmain.lib opengl32.lib glu32.lib

Conclusions

There are various issues in using GLUT and SDL with Watcom compiles. These issues are about the way Watcom compiles passes arguments to functions and about equivalence about types.
No one of them is a programming issue. They are about tools used to program (compiler and linker).

To conclude this document there are two pieces of code that are practical to use. They represent the starting part for applications using GLUT and SDL used by the author of this document

/*
 * GLUT and OpenWatcom
 *
 * Compile with:
 *
 * wcc386 /5s file.c
 * wlink option quiet name file.exe file file.obj 
 * 
 * or
 *
 * owcc -o file.exe file.c
 */
#include <stdlib.h>
#include <GL/glut.h>
#ifdef __WATCOMC__
#define GLUT_DISABLE_ATEXIT_HACK
#endif
/*
 * SDL and OpenWatcom
 *
 * Compile with:
 *
 * wcc386 file.c /5s /ei
 * wlink option quiet name file.exe file file.obj
 * 
 * or
 *
 * owcc -o file.exe file.c
 */
#ifdef __WATCOMC__
#pragma enum int
#pragma library ("SDL.lib")
#pragma library ("SDLmain.lib")
#pragma library ("opengl32.lib")
#pragma library ("glu32.lib")
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __WATCOMC__
#define SDL_main main
#endif

Copyrights

WATCOM, OpenWatcom, Windows, Win32, OpenGL, GLUT, SDL etc. are copyrights/trademarks of their respective owners.
For any feedback, suggestion or comment feel free to mail to me at the address: francesco [dot] nidito [at] gmail [dot] com
Otto per mille sul sito UAAR Sbattezzamoci con l'UAAR

AltStyle によって変換されたページ (->オリジナル) /