Search Postgresql Archives

Re: C++ User-defined functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks Craig,
 
I'm trying to compile a very simple test with Visual Studio (2008), but I get the following errors:
 
c:\program files\postgresql\8.3\include\server\pg_config_os.h(188) : error C2011: 'timezone' : 'struct' type redefinition
c:\program files\postgresql\8.3\include\server\pg_config_os.h(188) : see declaration of 'timezone'
c:\program files\postgresql\8.3\include\server\pg_config_os.h(197) : error C2011: 'itimerval' : 'struct' type redefinition
c:\program files\postgresql\8.3\include\server\pg_config_os.h(197) : see declaration of 'itimerval'
c:\program files\postgresql\8.3\include\server\c.h(97) : fatal error C1083: Cannot open include file: 'libintl.h': No such file or directory

I must be doing something wrong - I don't even have a libintl.h on my drive...
 
This is my .cpp file:
 
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
#define _USE_32BIT_TIME_T

#include "postgres.h"
#include <string.h>
#include "fmgr.h"
/* by value */
PG_FUNCTION_INFO_V1(add_one);
        
Datum
add_one(PG_FUNCTION_ARGS)
{
    int32   arg = PG_GETARG_INT32(0);
    PG_RETURN_INT32(arg + 1);
}
 
If you can help, that would be wonderful.
 
Thanks a lot,
 
George.
 
 
> Date: Tue, 10 Mar 2009 02:35:34 +0900
> From: craig@xxxxxxxxxxxxxxxxxxxxx
> To: oakmang@xxxxxxxxxxx
> CC: pgsql-general@xxxxxxxxxxxxxx
> Subject: Re: C++ User-defined functions
>
> George Oakman wrote:
>
> > I am trying to write a user-defined function in C++. Most examples are give in plain C. I would be very grafeful for a sample program/code-snippet in C++.
>
> It's just like any other C/C++ code mixing. You must make sure that any
> C-only headers are included within an `extern "C"' block, and declare
> any functions that'll be accessed via dlopen() etc as 'extern "C"' too.
> You may only use POD types, arrays of POD types, and structs of POD
> types (with no methods) in calls to/from C code.
>
> In other words, all PostgreSQL must see is plain C code, but your
> 'extern "C"' functions may call C++ methods and work with C++ objects
> internally.
>
> There's lots more information about this on the Internet. Just look for
> generic resources on calling C from C++ and vice versa.
>
> (I don't *think* there are any issues with libstdc++, though you'd
> probably have to make sure that no other program linked into Pg brings
> in a different version of libstdc++.)
>
> --
> Craig Ringer
>
> --
> Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general


Windows Live Hotmail just got better. Find out more!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux