2

The terms "unit" and "library unit" are used in many places on the web site, but I failed to find documentation or even definitions of these terms. The only description that I found is in "User's Manual/Supported language/Declarations/(unit|uses)". Also there is an example in "User's Manual/Using the compiler/An example with multiple files". As you can see, very scarce.

If I ever get a response, the next question is how are "units" related to modules described in "User's Manual/Supported language/Modules"? I suppose that "units" somehow relate to compilation, while modules relate to Scheme value names.

beroal
  • 369
  • 4
  • 14

1 Answers1

3

Unit is short for "unit of compilation", which is basically a compiled library. If you look at the source code for CHICKEN, you'll notice that each unit from the manual corresponds (roughly) to a source file. Each source file is compiled separately into a .o file, and these units are all linked together into libchicken.so/libchicken.a.

This terminology is not very relevant anymore, except when you're linking statically. Then you need (declare (uses ...)), which refers to the unit name. This is needed, because the toplevel of the particular unit needs to run before the toplevels that depend upon it, so that any definitions are loaded.

In modern code you'll typically use only modules, but that means your code won't be statically linkable. We know this is confusing, which is why we're attempting to make static linking with modules easier with CHICKEN 5, and reducing the need to know about units.

sjamaan
  • 2,282
  • 10
  • 19
  • And what is a "compiled library"? Is it a "*.o" file, a "*.a" file, a "*.so" file? – beroal Mar 13 '17 at 16:56
  • I would like to compile parts of an executable file ("o" files) separately. (First, I cat omit compilation of parts that have not changed. Second, I write in C too.) The linker ("csc" and "gcc") fails to link "o" files with an error "multiple definition of `C_toplevel'" if the "scm" files do not contain "declare (unit ...)". So I need to know about these "units". This should not be hidden. – beroal Mar 13 '17 at 17:01
  • I suppose that in a set of "scm" files that go into 1 executable file, every file should contain a unique unit name? – beroal Mar 13 '17 at 17:18
  • If you want to make use of separate compilation, you'll indeed need to explicitly declare a unit (or use the `-unit` flag), otherwise the compiler assumes you're creating a program with a standard entry point (unless you're creating a shared object file with `-dynamic`). – sjamaan Mar 13 '17 at 21:01
  • IMHO, a situation when an executable file or a shared object file is compiled from several source code files is pretty common. – beroal Mar 14 '17 at 06:22
  • Thanks for your answers. Things are more clear now. I wrote what I learned in my blog. http://beroal.livejournal.com/69518.html You can check whether it is correct. – beroal Mar 15 '17 at 09:37