Also, before you begin this example, you need to compile and link a C or COBOL function into a Dynamic Link Library (DLL).
If you already have a function that you would like to practice with, you might prefer to substitute yours in place of our sample. Otherwise, build a new DLL, using the source files provided below. See your compiler and toolkit documentation for guidance on building DLLs. You should also refer to IBM Smalltalk Programmer's Reference for guidance on the compiler options required by VisualAge. If you are running on AIX you should also see Building an AIX DLL.
If you build these source files in a directory other than the directory where VisualAge is installed, be certain that the include files or copybooks are in a directory that is in your INCLUDE or COBCPY path, respectively.
For your convenience, we have provided all the source files in the online version of this book, so you can copy them and do not have to retype them. When you paste the text into your editor, ensure that you remove any extra spaces, if necessary, especially in the make file and the command file. For the atm.cbl file, ensure it holds to COBOL column conventions.
After you have built the source files, you can proceed to Adding the parts.
Some Smalltalk environments require you to relink the virtual machine to access external functions. However, VisualAge gives you the ability to link to libraries dynamically, provided the following steps are taken when the library is built.
| temp | temp := AbtCLangParser parseFile: 'catm.h'. temp generateEntryTableForSource: 'catm.h' asTarget: 'catmtab.c'
The output is a C source file that inserts a table into your library when the file is compiled and linked into your library. VisualAge uses this table to access the functions in the library. For this example, the output will look like the following:
#include <esuser.h> #include <catm.h> EsDefinePrimitiveTable(Catm) EsPrimitiveTableEntry ("Atm", atm) EsEndPrimitiveTable
The entry point that VisualAge will be able to call directly is Atm.
MODULE_NAME = catm.w # the 'DLL' TABLE_NAME = Catm # declared as the 'entry point' to "ld" USER_OBJS = catm.o catmtab.o # my dispatch table and functions
SYSTEM_INCLUDE = -I/build/make.rs6000.vm/include USER_INCLUDE = -I. LDFLAGS = -H512 -T512 # Don't forget these! CFLAGS = -O -s $(SYSTEM_INCLUDE) $(USER_INCLUDE) LIBS = -lc $(MODULE_NAME): $(USER_OBJS) ld -o $@ $(USER_OBJS) $(LDFLAGS) $(LIBS) -e$(TABLE_NAME)
Note: | You will need to remove the cdecl from the function declarations in the sample files that follow if your compiler does not support this keyword. |
After you have successfully relinked your library you can proceed to Adding the parts.