Incorporation of object code using dynamic linking

Using dynamic linking instead of static linking to incorporate your module into RScheme is slightly more complicated.

First, you have to make sure you RScheme command rs was linked with a flag to ld indicating that the dynamic linker can use symbols in the executable to resolve unresolved symbols in dynamically linked code. The name of this flag varies between systems. On GNU/Linux, it is -rdynamic.

If rs was not built with this flag, you first have to rebuild it. Normally, if the object code is still around, you only have to redo the final link stage.

Next, you have to modify the Makefile generated by the off-line module compiler. You have to inform the C compiler to generate position independent code for all the C files of your module. This is necessary because the exact position of the final executable code may vary from one execution of the system to another. The exact form of this flag varies from system to system, but for the GNU C compiler it is -fPIC. In addition to informing the C compiler about position independent code, you have to tell the linker to generate a dynamically linkable library rather than just an object file, so instead of foo.o you obtain Again the way to do this varies from system to system.

At this point you are almost done. You don't need to recompile the RScheme executable, only make sure that it can find your file If your module is generally useful, you may want to install it together with other modules delivered with RScheme in the directory for this purpose (usually /usr/local/lib/rs/0.7.1/resource/modules). For application-specific modules, you simply need to make sure the directory in which the module is installed is in RScheme's search path for dynamically linked modules[1].



The default search path for modules, accessible by the module-search-path function in the mlink module, is the current directory, followed by [install]/resource/modules, followed by ~/lib/rs/modules.