martes, 12 de julio de 2016

Compile tds_fdw in Windows

After many trials and errors this is what I did in order to compile the tds_fdw code in a Windows 7 64 bits enviroment, with Visual Studio 2013

- Installation of dependencies:

- Postgres sources: I have installed Postgres 9.4.5 and downloaded the sources from here and I placed the sources inside the same installation directory.
You'll need this header file: libintl.h, which I got it from here

- Windows SDK, more specifically this library:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64\WS2_32.Lib

- Freetds, I got it from here:
I used last commit

- I used some guidelines from this adaptation of the odbc_fdw project in visual studio to create my own visual studio project

I used the debug and release profiles and macros like PGROOT to install the compiled dll in (PostgresDir)\lib

I did put the entire freetds folder in the visual studio project, however, not all the code files are included in the project, there are included only the required ones

These are the steps I made:

A) First of all I did put together the sources of tds_fdw in one folder (the .c and .h files)

B) There is a couple of files that are generated with freetds, but since I didn't compile freetds I added these files mainly from this repository:

getaddrinfo.h this is from

I got all these files from repositories, this is the 'walk on the eggshells' part; so far I didn't have any problems with my compilation (and the usage) but it is important to know that these files are not included in the freetds repository and I got them from different sources, so this might affect somewhere; so far in my tests I didn't have any problems

C) The file getaddrinfo.c has this declaration
Line 201: in_addr_t ipaddr;
This in_addr_t is missing, I declared it just above this line
typedef DWORD in_addr_t;

I got that solution from here

The same file has this missed reference 'hostip'
Line 263: strlcpy(hostip, inet_ntoa(sin->sin_addr), hostlen);
I commented out this line; I really cannot find any reference of this variable, so this is another starting point for improvements
In the same file I added the #include "getaddrinfo.h" line to make the compiler find EAI_OVERFLOW

D) I changed the sybdb.h, I added this reference:

#include <inttypes.h>

E) About this bjoern-utf8.h and bjoern-utf8.c files, I added the utf8_table definition located in bjoern-utf8.c into bjoern-utf8.h and excluded from the project the .c file

In debug mode 5 files are generated:

In other windows installations I noticed is better to compile in Release mode, because in debug mode you need this dll: MSVCR120D.dll
(A similar scenario is described here:

There are a couple of custom configurations made in the visual studio project but this is worth mentioning: In the project properties->Configuration Properties->C/C++->Output Files section I did set the Object File Name option as:


I mean the different .obj files are generated in different folders

If everything is correct you should be able to build the project and the dll will be generated and installed in (PostgresDir)\lib

You can download the visual studio project here

If you think I'm missing something please let me know

I think that's it, I don't think this is the best solution but I hope this is a starting point for a better implementation by someone else :)

Last but not the least, sorry for any grammar o spelling mistakes :) I hear constructive criticism with my writing as well

No hay comentarios:

Publicar un comentario