Writing a Glk Library: Use Existing glkstart or Build Your Own?

Greetings all. I’m curious about Glk development, in terms of creating a library. There are notes about the file glkstart.c:

“Remember, this is a sample file. You should copy it into the Glk program you are compiling, and modify it to your needs. This should not be compiled into the Glk library itself.”

Yet I do see that file compiled into CheapGlk, which my understanding suggests is a library, and thus that file should not be in place. I see Zerp has glkstart.c and glkstart.h provided. But Glulxe does not include those at all.

Based on the Makefiles for both Zerp and Glulxe, both seem to be relying on CheapGlk. So Glulxe uses the “glkstart” in CheapGlk (which would just mean the comment is inaccurate) but Zerp would seem to be using its own versions (which might conflict in some way). Or is the idea that someone just compiles something like CheapGlk in the way they want to use it? This would suggest: if someone is going to use the built-in glkstart.c and glkstart.h, they would compile CheapGlk with those files in place, but, if not, then they would include their own implementations and not include those files when they build CheapGlk.

I should note I’m learning a lot as I go so stuff that is probably obvious to C developers may not be to me. So far I’m creating MinGlk and GrueGlk to test out the ideas. Very early days!

That file should not be compiled as part of any Glk library (although the glkstart.h header file is part of the library, if it chooses to handle startup code this way). Indeed it isn’t compiled by cheapglk’s own Makefile, even though it’s included in the repository for reference. If the library defined the glkunix_startup_code and glkunix_arguments symbols, those definitions would clash with the definitions provided by applications like Zerf or Glulxe. The latter does define startup code, it just doesn’t have a single file glkstart.c. Instead, it has several bespoke startup files for different platforms/Glk libraries. The version compatible with cheapglk is here: glulxe/unixstrt.c at 0a975939ff83ef1edb199a694c38adc73369b5bf · erkyrath/glulxe · GitHub - it implements the same interface that cheapglk and others expect, but it doesn’t bear any resemblance to the sample file included in cheapglk.

1 Like

Perfect! Got it and understood. Oddly enough, I didn’t even check the CheapGlk Makefile, which would have been an incredibly obvious thing to do. Probably would have saved me time writing my own since my skills in that area on the rusty side of non-existent. (Just getting the mkdir and rmdir working on both Windows and *nix took me longer than anticipated.)

Much thanks on this info. This got me going in the right direction.