Creating Library (*.lib) and Object (*.obj) Files

 

There are occasions where user-written source code may harbour trade secrets, or simply represent a large corporate investment in development time.  In instances such as this, it may be in your best interest to secure this code before it is distributed, especially when models are to be sold or used by clients or partners in joint ventures.  Source code can be easily protected by providing it to clients in a pre-compiled (i.e. binary) format.  Any source files linked to a PSCAD project are by default compiled into separate object files, by whichever Fortran compiler is being used.  PSCAD also provides a utility to efficiently incorporate multiple object files into a single, compiled library file.  

 

Source files are linked to a project by one of two methods:

  1. Using the File Reference component

  2. The Additional Source (.f) Files field in the Project Settings dialog

Object (*.obj) Files

Normally, when a source file is linked to a project, the Fortran compiler used to compile the project will automatically create a compiled object (*.obj) file for each linked source file.  This file is placed in the project temporary folder.  The user may choose to supply clients with these compiled object files, rather than the source code.  This is fine if only one or two source files are involved.  Large projects however, can contain many source file links, and supplying an object file for each source file can quickly become cumbersome.  One way to circumvent this problem is to merge all source routines into a single file.  This process can also be tedious, and may create problems in the on-going development of the source code.

Static Library (*.lib) Files

A more efficient means for merging many source files together is to combine all the individual object files into a single compiled library (*.lib) file.  PSCAD provides an easy avenue to create a compiled library file for any library project (*.pslx) file, provided that links to the source files are set within the library project.  In library projects, this may be accomplished through the use of File Reference components.

Creating a Library (*.lib) File

The first thing to consider before creating a library file is the Fortran compiler.  Each Fortran compiler will create compiled files, which may or may not be compatible for use with other compilers.  In other words, it is important to know what type of Fortran compiler the client is using, so that the files provided are compatible.  Most PSCAD users will create an equivalent file for each supported Fortran compiler.  These files can then be placed in the appropriate directories as described in Additional Library (*.lib) and Object (*.obj) Files.

 

Step 1:

 

Create a new library project as described in Creating a New Project (or edit an existing library), and then link each source file to be included in the compiled library (*.lib) file using File Reference components.

 

 

Step 2:

 

Right-click on the Library name in the Workspace and select Create Compiled Library (*.lib):

 

 

When the Create Compiled Library (*.lib) function is invoked, PSCAD will create a temporary folder for the library project located in the same directory as the project (*.pslx) file.  In it will be placed the compiled library file (*.lib), plus an individual object file (*.obj) for each linked source file.