Creating your own library repository

Discussions related to the code libraries supplied with BB4W & BBCSDL
RichardRussell

Creating your own library repository

Post by RichardRussell »

I recently received a very interesting enquiry: where should a BBC BASIC software developer put libraries that he has developed, so that they can be used by multiple programs?

The most straightforward answer, and it's the approach I usually adopt, is to copy them into the same place that the supplied standard libraries are, in other words @lib$ (so in the case of BB4W that will typically be C:\Program Files (86)\BBC BASIC for Windows\LIB). But this isn't ideal for a number of reasons: it's a 'protected' location that can only be written to with admin privileges. It's (potentially) a location shared between multiple users, not all of whom should necessarily have access to the same 'custom' libraries. And it's a location that doesn't get automatically backed up.

If you want to take advantage of the ability of BBC BASIC to embed libraries and other resource files in 'compiled' executables (or 'application bundles' in the case of BBCSDL) they must be stored in either @lib$ or @dir$ (or a subdirectory thereof). If putting them in @lib$ is ruled out for the reasons above, that leaves only @dir$. But that's not ideal either, because each program (project) will have a different @dir$ so you could end up with multiple copies of the same library, in different places, which is a nightmare for version control and maintenance etc.

Fortunately there's a solution: directory links! You can get the best of both worlds by creating a shared library repository, anywhere in the file system of your choosing (perhaps somewhere automatically backed up to DropBox or OneDrive) and then creating links in each of your project directories to this repository. The command line syntax for creating a link to a directory, in Windows, is mklink /d \project\lib \shared\lib. Linux and MacOS have similar capabilities.

Now every project has its own library directory, which being (or appearing to be) a subdirectory of @dir$ has the advantage of allowing embedding, but which is in reality a single library repository shared by all those projects!