Creating PostgreSQL C extensions on Windows platform -


i'm having problems getting simple test functions postgres link and/or run on windows, having tried both command line , visual studio. have found little documentation , no working templates this.

i'm not used compiling tools in windows , i'm new postgres may missing basic. directions appreciated!

using: windows 8.0 (64-bit), cl.exe 18.00.21005.1, link.exe 12.00.21005.1, postgresql v.9.3.4 (binary install).

this sample code documentation have simple, added pgdllexport invocation:

#include "postgres.h" #include "fmgr.h"  pg_module_magic; pg_function_info_v1(add_one);  pgdllexport datum add_one(pg_function_args) {     int32   arg = pg_getarg_int32(0);      pg_return_int32(arg + 1); } 

in cl command file collected following include paths:

/i "c:\program files\postgresql\9.3\include\server\port\win32_msvc" /i "c:\program files\postgresql\9.3\include\server\port\win32" /i "c:\program files\postgresql\9.3\include\server\port" /i "c:\program files\postgresql\9.3\include\server" /i "c:\program files\postgresql\9.3\include" 

and running:

cl /c add.c @includes link /dll add.obj "c:\program files\postgresql\9.3\lib\postgres.lib" 

it compiles , links without errors or warnings. put created add.dll in postgres \lib directory , define corresponding function logged in psql user postgres:

create function add_one(integer) returns integer 'add','add_one' language c strict; 

where following error:

error:  not load library "c:/program files/postgresql/9.3/lib/add.dll": %1 not valid win32 application. 

the result same when building dll in visual studio.

the extensions intended write more complex , included "funcapi.h" using composite arguments , returns. in case compiled without problems, failed @ linking stage errors of type:

error lnk2019: unresolved external symbol _get_call_result_type ... error lnk2019: unresolved external symbol _blesstupledesc ... error lnk2019: unresolved external symbol _heap_form_tuple ... 

same wether using command line or msvc, , checking lib path , trying adding possible .lib dependencies in \lib command line. tried different calling conventions.

but, anyway, need simple dll-exports working first, , maybe solutions related same issue.

i guess may have system defaults included cl doesn't match (32/64-bit?), since source includes headers postgres project i'd hoped automatically resolved , don't know how proceed this.

i wrote blog on topic may useful; see compiling postgresql extensions on windows visual studio.

the issue headers mention fixed in 9.4 series. i'll see getting backpatched branches.

rather hacking c.h should instead specify define on command line:

/dwin32 

you should ensure code compiled plain c:

/tc 

and of course must running under correct visual studio command prompt environment, x86 or x64 compiler depending on desired target. if you're not sure, can check running cl.exe without arguments; it'll print target architecture.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -