Prerequisites
You should complete the Getting Started lab and the Libraries module before starting this lab.
Overview
The goal of this lab exercise is to successfully compile, link, and run serial codes that use static and dynamic libraries.
Exercise
Exercise 1
- Logon to one of the login nodes, ctclogin1 or ctclogin2, or if you are in the collaboratory, login to one of the machines there.
- If you are on a Windows machine, use the Microsoft Terminal Server client.
- If you are on a non-Windows machine, use a Citrix client.
References:
Getting Started module
Access Hottip
- Move to your home directory on H: and create a new folder for this exercise if you wish.
-
- Start an editor. Even if you don't use its other features, Microsoft Developer Studio has a better editor for program code than notepad, wordpad, or vi. On your desktop (make sure it's the one in your terminal client window if you're working on a ctclogin node) go to Start:Programs:Microsoft Visual Studio 6.0:Microsoft Visual C++ 6.0 or Start:Programs:Compaq Visual Fortran 6:Developer Studio.
- Also start a command window and move to the directory where you have placed your files.
- Compile square, but use the /c flag to suppress linking.
- Use the lib command to create a library called square.lib containing square.obj.
- Compile mysquare and include square.lib on the command line to make it available to the linker
- Run mysquare. Be sure to give it a number as input.
- To prove that the static library was used only a link time, try deleting it and rerunning mysquare. It should still work.
Exercise 2
Now it's time to create and use a dynamically linked library.
- Open an editor (if you didn't do the first exercise, look at the suggestion there) and a command window.
- Make sure square.c and mysquare.c or square.f and mysquare.f are in your current directory. They should be if you just finished exercise 1.
- Edit square so it will export its name.
- Compile square into a dll.
- Compile mysquare and include square.lib on the command line so that the linker will resolve the reference to square() in the dll. Note that this command is identical to the build command you used for exercise 1.
- Run mysquare and see that the output is the same as from the previous exercise.
- To prove that you are using the dll, try renaming it and rerunning mysquare.
Solution
Cleanup