- Welcome to Simply Fortran
- Purchasing and Activating Simply Fortran
- Using Simply Fortran
- The Simply Fortran Interface
- Editing in Simply Fortran
- Projects in Simply Fortran
- Building Projects
- Launching Projects
- Debugging Programs
- External Tools
- Version Control
- Options and Configuration
- Licensing
Linking Libraries
Simply Fortran can handle the mechanics of linking to external libraries using two techniques. Each method offers advantages, which are explained below.
Adding Libraries to a Project
The first technique involves adding a library file directly to a Simply Fortran project. This process is identical to adding a source file to a project. First, right-click on the project tree in the Project Pane and select “Add File(s)…” Using the file selection dialog, navigate to the library file for inclusion; generally speaking, the file should have a .a or .dylib extension. Select the file and press Open button.
The library file should now be in the project. Libraries are binary files and cannot be edited in Simply Fortran.
Using Compiler Flags
Libraries can also be included using compiler flags. To include a library via compiler flags, the library’s directory must be added to the list of library search directories. From the Project Options dialog, accessible by right-clicking the project tree and selecting “Options,” click the “Search Directories…” button. In the Directories dialog, select the “Library Directories” tab. Click the “Add…” button and select the containing directory from the dialog.
After adding the library’s directory to the list, press the “Ok” button. Next, in the Project Options dialog, add the desired library via a linker flag. For example, if the library file were named libblas.a, enter the following:
-lblas
In the example above, notice that the “lib” prefix was excluded because GNU Fortran implicitly assigns this to the beginning of the library name.
Libraries with Supporting Module Files
If one is attempting to include a modern Fortran library that ships with a module file, Simply Fortran must be instructed as to where to find the module file. During the build process, Simply Fortran will construct a module directory within the project’s containing directory by default. However, this folder is emptied each time a clean operation is requested. Instead, the external module file should be placed in a safe location.
To include a directory in the project as a module search directory, which is necessary for external modules, open the Directories dialog by click the “Search Directories…” button in the Project Options dialog. In the Directories dialog, select the “Include/Module Search Directories” tab, click the “Add…” button, and select the proper directory. Once complete, press the “Ok” button in the Directories dialog.
Errors Related to Module Files
When using precompiled module files, normally ending with the .mod extension, the compiler may occasionally issue errors about module file versions or unrecognized module file type. The GNU Fortran compiler is only compatible with module files compiled with the GNU Fortran compiler. If attempting to use a module file generated using another compiler, it most likely will not work properly. Additionally, development of GNU Fortran is ongoing, and occasionally the internal module file format is updated in an incompatible manner. In these instances, the source code for the module must be recompiled for the version of GNU Fortran shipped with Simply Fortran.
If a user has access to the source code containing the interfaces to the library functions, it may be easier to include this source file into the project directory rather than relying on precompiled module files.