Log in

No account? Create an account
A few tips for compiling c functions for PostgreSQL 8.0 on Windows - Nick [entries|archive|friends|userinfo]

[ website | gagravarr.org ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

A few tips for compiling c functions for PostgreSQL 8.0 on Windows [Feb. 8th, 2005|01:15 pm]
At work, we make great use of the xml functions that come in the contrib/xml2 directory with PostgreSQL. They let us store XML in the database, query it with xpath, transform it on the way out with XSLT, and do other cool in-database xml type stuff.

Annoyingly, PostgreSQL 8.0.1 for Windows doesn't come with the xml2 modules as one of the extras. So, since I needed to do some windows postgres work first, I had the fun and joy of figuring out how to do the building.

(Tom is going to write something up on building the xml2 modules for windows, this is just a general guide to module building).

First up, don't try using the cygwin mingw cross compiler and the headers that come from the install if you pick "install development stuff". They just don't contain enough for anything more than the most basic modules to compile.

Second, don't try grabbing the headers from a linux build, then copying the headers from the postgres install over the top. You might just get it to work, but it really isn't worth the hassle....

Instead, head over to MinGW.org and grab the MSYS and MinGW packages. Install these, and fire up a mingw shell. Ensure that there aren't any cygwin bits in your path, then run configure and make against the postgresql 8 source tree. All being well, it'll go along on its way.

Once you have a mingw build tree, unpack your modules inside here, and use this to build them against. Be sure that you're still using a MinGW compiler (the cygwin one is no good, as you need mingw/vc++ style linking and symbol tables, not cygwin ones). Be sure that any third party libraries you link against were built for vc++ or mingw, and not cygwin.

Finally, be aware that your module dll needs to live in the postgres /lib/ directory, but any dependent dlls need to be in the postgres /bin/ directory. Also, the sql install script should just have something like "AS 'libpgxml' LANGUAGE 'c'" for libpgxml.dll placed in the /lib/ directory (don't include the .dll, don't include the lib/).

(You can also compile with cygwin gcc and -mno-cygwin, but it is much more hassle. Just give in and install the mingw packages)