| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Cogsys extensions work in exactly the same way, with a powerful new feature. Normally, the main program can access the dynamically loaded code, but never the other way around. A moment's reflection shows why this so--dynamic libraries are naturally designed to work with many different programs. For instance, a paint program may call a library to draw a JPEG image, but a web browser may also use that same library to display an image. The JPEG library doesn't know what program is calling it, and it doesn't care--there is no reason why the JPEG library would need to know, for example, what font the word processor is currently in. If it did, what would it do when it was being called by the paint program? Thus, traditional dynamically linked libraries do not access the main program; it is a one-way street only.
Under Unix, the "global" declaration for variables works with shared objects. The main executable just needs to be linked with the -rdynamic and -ldl flags like this Makefile example:
cogsys: ${CC} -c -I/usr/include/rtlinux ${ALL_SOURCE_FILES}
${CC} ${ALL_OBJECT_FILES} \ -rdynamic -ldl -o $ `sdl-config --cflags --libs` \ -lstdc++ -lSDL_ttf -lm
The next section describes the details of creating an extension.