Re: Compiling C function with VC++ for Windows version

From: Edwin Quijada <listas_quijada(at)hotmail(dot)com>
To: <ringerc(at)ringerc(dot)id(dot)au>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Compiling C function with VC++ for Windows version
Date: 2012-01-12 17:55:30
Message-ID: BAY155-W20AF01DFC939EC35CF31B4E39F0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Date: Thu, 12 Jan 2012 13:45:06 +0800
From: ringerc(at)ringerc(dot)id(dot)au
To: listas_quijada(at)hotmail(dot)com
CC: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Compiling C function with VC++ for Windows version




On 12/01/12 11:06, Edwin Quijada wrote:



Hi!
I am trying to create a C function for windows in Postgres
compiling with VC++ 2008 Express Edition. I did this function
for Linux without problem using gcc and tried to do the same
in Windows but in Windows was imposible. The function compile
fine but when I tried to run from Postgres it down the server
in windows but in Linux the same function run perfect.


You haven't provided enough information for anyone to help you.

How are you compiling your function? Using pgxs, or some other way?

What's the full source code of the function?

Where does the server crash when it crashes? You might need to get a
backtrace of the server crash to help you figure out why your
function crashes it. See this documentation on getting a backtrace
of a Pg backend under windows:


http://wiki.postgresql.org/wiki/Getting_a_stack_trace_of_a_running_PostgreSQL_backend_on_Windows




The function just try to get a string value and pass to
postgres. Reading somebody told me that I need to compile the
function using VC++ not gcc in Windows so I downloaded VC++
2008 Express but I dont know what directives compilation I
need as gcc in windows and Linux.


If you are using a standard binary distribution of PostgreSQL then
yes, you should use Visual C++, preferably the same version of
Visual C++ that was used for that version of PostgreSQL. Specify
your version of Pg.---------------
Ok.This is the way that I compile. Linux this way works fine and I use the modules compiled. of course, Linux I compile from source and I use gcc.
C:\mingw\bin\gcc -g -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I "C:/Program Files/PostgreSQL/8.3/include/" -I "C:/Program Files/PostgreSQL/8.3/include/server" -I "C:/Program Files/PostgreSQL/8.3/include/server/port/win32" -DEXEC_BACKEND "-I C:/Program Files/PostgreSQL/8.3/include/server/port/win32" -c pg2.c -o pg2.oC:\mingw\bin\gcc -shared -o pg_server_function.dll pg2.o -L "C:\Program Files\PostgreSQL\8.3\lib" -lpostgres
It is using gcc in windows version
This is the module that I want to compile
<code> #include "postgres.h"#include "fmgr.h"#include <stdio.h>#include <string.h>
#include "libstd.h"
#ifdef PG_MODULE_MAGICPG_MODULE_MAGIC;#endif

PG_FUNCTION_INFO_V1(pg_server_id);
Datum pg_server_id(PG_FUNCTION_ARGS){ char mac[30]; text *new_t = (text *) palloc(30); int32 arg = PG_GETARG_INT32(0);// getmacwindows(mac);// SET_VARSIZE(new_t, strlen(mac) + VARHDRSZ); memcpy(VARDATA(new_t),(text *)mac,strlen(mac)); PG_RETURN_TEXT_P(new_t);}

PG_FUNCTION_INFO_V1(pg_serverid);Datumpg_serverid(PG_FUNCTION_ARGS){ float8 mac; int32 arg = PG_GETARG_INT32(0); // arg++; mac = getmacwindows2num(); // PG_RETURN_FLOAT8(mac);}

PG_FUNCTION_INFO_V1(one); Datum one(PG_FUNCTION_ARGS) { int32 arg = PG_GETARG_INT32(0); int32 x= ++arg; //mac2num(); //getmacwindows(mac); PG_RETURN_INT32(x); }</code>
The function is simple just get the mac address of the PC. Now, I am trying to use VC++ 2008 Express to compile this module but I dont know how to pass all these parameters using VC++
In this example is 8.3 but I tried with 9.0 too
This compile fine the problem at running timme this crash down my server..:(Any help will be so apreciated.

--

Craig Ringer

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Manoj Govindassamy 2012-01-12 18:12:47 Re: PG synchronous replication and unresponsive slave
Previous Message Pavel Stehule 2012-01-12 17:14:34 Re: unnest array of row type