This small tutorial was written originally in the PD forum.
The main resource for creating externals for PD is Iohannes Zmoelnig's How to write and external for PD
Even if Microsoft Visual C++ offers an integrated environment for developing there can be some good reasons for giving a try to the old-man "unix" way of compiling, which in windows is best represented by MINGW32 and cygwin. Both offers linux-like environments (i.e. command line tools) for compiling and other shell tasks which, sometimes, in windows are
a pain in the ass. There are at least three good reasons for giving a look at mingw:
1) gives strong linux compatibility on external compilation (almost same command lines arguments etc.)
2) there is the possibility to use makefiles in an almost straightforward way (with minor modifications to linux makefiles).
3) no dependency on expensive MS programs (except for the small, bug-free Operating System ;-)
I did this exercise by porting the E. Lyon "LyonPoutpourry" externals for win
(http://www.sarc.qub.ac.uk/~elyon/LyonSoftware/Pd/). Give a look at the win source package: inside there is a makefile for darwin (MAC) linux and win. I added the latter, and as you can see the modifications are minor.
----------- 1. Prelude: compilation environment ------------------
First of all we have to set once for all the compilation environment. Let's forget for the moment cygwin and concentrate on mingw32 (http://www.mingw.org/). The following is taken from (H.C. Steiner's wiki http://www.puredata.org/docs/developer/mingw)
Download the MinGW package installer and run it:
(http://prdownloads.sourceforge.net/ming … -5.1.1.exe)
Choose
the Candidate distribution. Install the defaults and add the g++
compiler, g77 compiler, and MinGW make or you can just download my
MinGW install, MinGW-Pd.tar.bz2, and uncompress it so that its
installed into C:\MinGW.
Then we need MSYS which is a shell (an interpreter of the commands, like a colorful dos prompt ;-)
http://prdownloads.sourceforge.net/ming … 1.0.10.exe
Now
you will be using the MSYS shell that was installed from the MSYS
installer. You can launch it from the Desktop shortcut or Start ->
Programs -> MinGW -> MSYS -> msys
----------- 2. Allegro: compilation trial ------------------
a. open MSYS
b. at the prompt type:
cd c:
(or the drive you whish to go for the pd external compilation)
c. go to the external directory (note the backslashes instead of slashes !),
mine is external-compiling. Inside I have helloworld.c
cd alberto/backup/PureData_Archive/patches/AlbertoZ/external-compiling/
d. copy m_pd.h (from the PD distribution directory) into external-compiling
(or whatever is its name)
e. type:
gcc -c helloworld.c -o helloworld.o
f. type:
ld -export_dynamic -shared -o helloworld.dll helloworld.o c:/Programmi/pd039ext4/bin/pd.dll
(this
is the linker step. note that I linked to a particular version of
pd.dll - 0.39 extended test 4, so probably (I'm not sure about this)
the external will run on 0.39 only. Can someone confrm this?)
g. If everything was ok then you should have a helloworld.dll in your directory. Move it on the extra folder of your pd distribution (I assume that extra folder is in the pd predefined path) and make a new patch with the helloworld object. Again, if everything is correct, you should have a "Hello world!!" printed on the console.
----------- 3. Adagio: makefile ------------------
A makefile can be used for compilation. Even if a simple helloworld application does not need it, complex programs may do. The makefile.win is here. Modify it according to your path. Make sure you have
helloworld.c
m_pd.h
makefile.win
in your directory. Now type at MSYS prompt:
make -f makefile.win
This will automatically produce the object, the linker step (the dll) and will copy the helloworld.dll in the extra folder of you pd distribution (overwriting the existing one ;-).
----------- 4. Allegro con brio: conclusions ------------------
Why not give a try to the old-man compilation on Win? :-)
----------- 5. Minuetto: greetings ------------------
I apologize if I said some crap somewhere, just let me know if it doesn't work. Have fun!