Compiling a PLT Extension With Visual Studio
Posted by Peter on April 2, 2006
If mzc doesn’t work properly for you, and it doesn’t work (completely) for me, or if you simply want to use Visual Studio for your coding and compiling then you have a bit of work ahead of you. Actually the process itself isn’t that complicated, but good luck figuring out how to do it with the documentation, which is a bit sketchy on how to do things without mzc.
First create a new win32 project and choose the .dll option. (the finished extension is a dll file that Scheme will load at run-time).
Next go to tools->options->projects->VC++ directories (in Visual Studio .Net), and add the path for the PLT libraries and include files to the directories searched for .h and .lib files at compile time. (the directories to add are …\PLT\include and …\PLT\lib\msvc respectively).
Thirdly go to Project->Properties->Linker->Input and add the following three files to the additional dependencies: mzdyn.obj, libmzsch301_000.lib, and libmzgc301_000.lib. Actually you don’t need all of these, but it doesn’t hurt to include them just to be sure.
Finally create a new .def file (for example myproject.def) with a text editor. The body of this file should be the following:
LIBRARY [name of project (the output file minus the extension) goes here] EXPORTS scheme_initialize scheme_reload scheme_module_name scheme_initialize_internal
Now add this file to your project (as if it were a new source file), and go to Project->Properties->Linker->Input again and enter the name of this file for the Module Definition File entry. This .def file tells the compiler that these are functions which the .dll needs to export, and that they have to be named exactly as shown (because the Scheme interpreter expects to find them as such, and if they aren’t present the extension will not be loaded). The scheme_initialize_internal function is provided by a library, you don’t need to write it. The other three functions you must define (as is outlined in the documentation). You don’t need to mark them in any special way for export, the .def file takes care of that.
Now, if you want a tutorial on writing an extension, well that is the job for a different post.