Creating an FLTK Hello World GUI executable under the Watcom IDE and debugger

From Open Watcom

Revision as of 21:11, 18 July 2008; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

Creating a first standalone program is not actually difficult once you know a few wrinkles and my intention is smoothing the path.

The largest problem after installing and compiling the library itself is sorting out the linker include libraries.

 Create or use a subdirectory somewhere and we can call this a workspace.
 Copy the example source named quite remarkably "hello.cxx" from the FLTK /test/ directory to your working directory. 

We are going to build this program outside of the library and linked to the library files you compiled earlier.

 the IDE does not like C++ fiies with the extention .cxx so rename it to hello.cpp  (applies to standard OW, version < 1.8)
 Copy file config.h from the FLTK build directory to your work directory. (quickest way to get things running if not a nice practice)
 Fire up the Watcom IDE.
 Create a new project in your work directory, perhaps name it hello
 Add hello.cpp to the project.

By all means try compiling and linking, it will not work.

 Go into menu options, C++ compiler switches
 At the end of the include directory string add ;c:\compiles\fltk13 changed of course to the path you used as the root of 
 the FLTK library you built earlier. (don't miss out the path item separating semicolon)
 In include files add C:\compiles\demo-fltk\config.h changed to the path you are using as a workspace and is the config.h 
 file you copied earlier.

This is so that any included headers get to see the preprocessor flags.

 Close, nothing else needs changing in the compiler settings but you can change optimisation, debug status as you wish.

Now the the important information, how to set up the linker. This is tricky, especially with static links.

You can try compiling and this will confirm all is ok but link fails.

Go to menu, options, Windows linking switches

There are several ways of telling the linker what to do. There are a lot of includes and that is awkward to type into or paste into the edit boxs, so I will show you a better way, easier anyway.

wlink is a complex program with many command line and control features (try wlink /? from the command line to see)

 Where the configuration page says Other options type in the name of a control file, just a filename prefixed by @
 For example @hello-link-include.txt

Do NOT use the file extention .lnk, ever with Windows! You would get a nasty surprise as the contents vanish as it magics into a shortcut link (and invalid).

 Close the configure dialog, no other changes needed.
 Using a text editor create the file you just named in your working directory.

wlink accepts a list of commands and can be from a file.

Here are typical contents including a shopping list of libraries. I doubt all are needed but the linker only adds code as required.

 ## path to the precompiled FLTK .lib files
 LIBPath c:\compiles\fltk13\bin
 ## Now the library files to link to your program
 ## As you can see you can split this onto several lines.
 Library mt7rdll.lib,fltk.lib,wsock32.lib,comctl32.lib,clbrdll.lib,plbrdll.lib
 Library kernel32.lib,user32.lib,gdi32.lib,winspool.lib,comdlg32.lib
 Library advapi32.lib,shell32.lib,ole32.lib,oleaut32.lib,uuid.lib
 Library odbc32.lib,odbccp32.lib
 Hit compile, or run, all being well Hello World! will pop up as a Windows panel.

If debug is turned on that will be working.

Expect around a 240k executable if debug is turned on. It is static linked and is therefore complete. Without naming names that is compact relative to some of the alternatives, but to be fair they provide more eye candy.

That is all folks, dead easy.

Whether the cross platform working can be done remains to be seen.

OS/2, Linux, BSD, QNX, Win32 all might be possible. FLCK handles OS/2 via a different method at the moment, same for Linux and Mac (via X). All those are known to Watcom. I expect news of what can and cannot be done would create some interest.

Personal tools