6 Creating Libraries and Solutions

Suppose one has not just a single program but some more general functions that one wants to put into a library. Therefore a solution is needed. Here's how to create a solution:

  1. Create a directory for the solution.
  2. Under the solution directory, create a directory for the library. Here we name it "library".
  3. Under the "library" directory, create a project file for the library where the value of the target declaration is set to library.
  4. Put the library functions to some source file under the library directory. Here we name it library_functions.cminor.
  5. Under the solution directory, create a directory for the program. Here we name it "program".
  6. Under the "program" directory, create a project for the program where the value of the reference declaration points to the project file of the referenced library.
  7. Put the source code using the library into some source file under the "program" directory.
  8. In the solution directory, create a solution file with an extension .cminors. Here we name it solution.cminors.
  9. In the solution file declare paths to the project files using project declarations.

6.1 Library Files

Here's the contents of library_functions.cminor:

And here's the contents of the library.cminorp project file:

6.2 Program Files

Here's the contents of the program.cminor file using the library:

And here's the contents of the program.cminorp project file:

6.3 Solution File

Finally here's the contents of the solution.cminors soution file:

6.4 Building the Solution

> cminor build solution.cminors

Under the solution directory the compiler creates an assembly directory. Under that directory there's the directory matching the configuration used to build the solution. Under the configuration directory, the compiler copies the assembly files for each project included in the solution, and also the assembly file of each referenced library of those projects.

Here's the directory structure of the solution:

        |
        +--solution
           |
           +--solution.cminors
           |   
           +--assembly
           |  |
           |  +--debug
           |  |  |
           |  |  +--library.cminora
           |  |  |
           |  |  +--program.cminora
           |  |
           |  +--release
           |     |
           |     +--library.cminora
           |     |
           |     +--program.cminora
           |
           +--library
           |  |
           |  +--library_functions.cminor
           |  |
           |  +--library.cminorp
           |  |
           |  +--assembly
           |     |
           |     +--debug
           |     |  |
           |     |  +--library.cminora
           |     |
           |     +--release
           |        |
           |        +--library.cminora
           |
           +--program
              |
              +--program.cminor
              |
              +--program.cminorp
              |
              +--assembly
                 |
                 +--debug
                 |  |
                 |  +--program.cminora
                 |  |
                 |  +--library.cminora
                 |
                 +--release
                    |
                    +--program.cminora
                    |
                    +--library.cminora
        

6.5 Running the Program

> cminor run assembly/debug/program.cminora
1 + 2 - 1 == 2