On Scheme

Thoughts on Scheme and teaching Scheme

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]

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.


3 Responses to “Compiling a PLT Extension With Visual Studio”

  1. There is a lot easier way normally. Ok, it is already a long time ago that I actually did it myself on Windows, but since me and a friend wrote sPico already 2 years ago, which is used under windows too, we needed to compile it. Finding out how to write this fairly descent is fairly difficult indeed. After a long search we found out that if you use visual studio express for example, and the compiler is set in the path, (including libraries etc) which you can easily do with the bat-files of visual studio, you can compile extensions using drscheme itself. If you want to try it just run the make.ss of our sPico project. Makefiles in scheme, how cool is that! 🙂
    Under linux of course it all goes a lot easier since compilers are standardly installed and the path+lib is standard correct. Also for mac it is a lot easier. In both of them, if you just run make.ss without configuring compilers yourself, it works perfectly.

  2. Ryan Hicks said

    Thanks for the def file tip 🙂

    I was just fighting to get the exports to work in my extension to work…

  3. playing provides

    Compiling a PLT Extension With Visual Studio « On Scheme

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: