FAQ
Hi,



I have a problem when trying to debug a shared library developed in C. I’m
following the steps included in the docs, in chapter 33 (extending SQL),
section 33.9 (C-Language functions)
http://www.postgresql.org/docs/8.2/interactive/xfunc-c.html



I’ve successfully compiled the example tablefunc.c which is included in
http://developer.postgresql.org/cvsweb.cgi/pgsql/contrib/tablefunc/



I’m using Eclipse 3.2 and have installed mingw. The problem I have is that I
cannot debug the functions. When trying to debug, I choose the option “C/C++
attach to local application”. Then a list of processes to select appears.
The only option I can choose is pgAdmin3.exe. When I choose it and open a
SQL script in the pgadmin and execute the function I’m trying to debug, the
function works properly but in doesn’t’ enter the debug.



This is the code I use to create the function. It’s linked to the dll
compiled with Eclipse.



CREATE OR REPLACE FUNCTION mi_crosstab(text)

RETURNS SETOF record AS

E'D:\\\\eclipse\\\\workspace\\\\tablefunc_lib\\\\Debug\\\\tablefunc_lib',
'mi_crosstab'

LANGUAGE 'c' VOLATILE STRICT;

ALTER FUNCTION mi_crosstab(text) OWNER TO postgres;



I have seen that there are several processes called postgres.exe in the
system administrator window. I have managed to make them appear in the list
I mentioned, but when I select them in the debug option, I get the following
error message: “Attach to process failed”.







I’m also trying to debug using Microsoft Visual C++ 6.0. With this option I
cannot even compile any library.



This is the simple code I’m trying to compile:





extern "C"{

#include <postgres.h>

#include <string.h>

#include <fmgr.h>

};



PG_MODULE_MAGIC;



PG_FUNCTION_INFO_V1(add_one_float8);



__stdcall DllMain( HANDLE hModule,

DWORD ul_reason_for_call,

LPVOID lpReserved

)

{

return TRUE;

}





extern "C" {

__declspec(dllexport) Datum add_one_float8(PG_FUNCTION_ARGS)

{

/* The macros for FLOAT8 hide its pass-by-reference nature. */

float8 arg = PG_GETARG_FLOAT8(0);



PG_RETURN_FLOAT8(arg + 1.0);

}



};





When doing so I get 3 warnings referred to the MAGIC FUNCTION declaration,
and the function doesn’t work.



warning C4273: 'Pg_magic_func' : inconsistent dll linkage. dllexport
assumed.

warning C4273: 'pg_finfo_add_one_float8' : inconsistent dll linkage.
dllexport assumed.

Linking...

LINK : warning LNK4075: ignoring /INCREMENTAL due to /FORCE specification

Creating library Debug/Postgres_dll.lib and object Debug/Postgres_dll.exp



Postgres_dll.dll - 0 error(s), 3 warning(s)





The Pg_magic_func is declared in the header file fmgr.h, I have checked it
but I don’t see any error there.





Please, if you could provide me some feedback, I’d be really grateful!!



Thanks,



Aurora

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-hackers @
categoriespostgresql
postedJul 23, '07 at 4:04p
activeJul 23, '07 at 4:04p
posts1
users1
websitepostgresql.org...
irc#postgresql

1 user in discussion

Aurora Sánchez: 1 post

People

Translate

site design / logo © 2022 Grokbase