Hi,
I have some old code for extension functions in Postgres 8.0. And, I
am trying to make it work with Postgres 8.2.

One problem is about the Magic Block.
The extension functions was developed by C++ mixed with C.
The code is like:

extern "C" Datum spgistinsert(PG_FUNCTION_ARGS)
{
...
}

I have added enough PG_MODULE_MAGIC; to the source code. (Also,
include 'fmgr.h' and 'postgres.h')
But, when I create the function inside Postgres, it still complains as
following:
ERROR: incompatible library
"/home/hepei/bin/Chameleon/lib/libspgist_trie.so": missing magic block
HINT: Extension libraries are required to use the PG_MODULE_MAGIC macro.
STATEMENT: /* Load the trie extension */
/*------------------------ */

load '/home/hepei/bin/Chameleon/lib/libspgist_trie.so';
ERROR: incompatible library
"/home/hepei/bin/Chameleon/lib/libspgist_trie.so": missing magic block
HINT: Extension libraries are required to use the PG_MODULE_MAGIC macro.

I am capable to define a simple function in a single file by C, and
make it work with postgres 8.2. However, my old code is more complex,
which involves more source code, library, and it is also using both
C++ and C. So, I am not sure where the problem comes from, and how to
solve it.

Thanks
Look forward your reply
--
Pei

Search Discussions

  • Takahiro Itagaki at Apr 2, 2010 at 5:47 am

    Pei He wrote:

    The extension functions was developed by C++ mixed with C.
    ERROR: incompatible library
    "/home/hepei/bin/Chameleon/lib/libspgist_trie.so": missing magic block
    HINT: Extension libraries are required to use the PG_MODULE_MAGIC macro.
    You can use extern "C" blocks for PG_MODULE_MAGIC, PG_FUNCTION_INFO_V1,
    and function declarations:

    extern "C"
    {
    #include "postgres.h"
    #include "fmgr.h"

    PG_MODULE_MAGIC;

    PG_FUNCTION_INFO_V1(your_function);
    extern Datum your_function(PG_FUNCTION_ARGS);
    }

    However, you should very carefully use C++ exceptions and destructors
    in your module because PostgreSQL uses siglongjmp; C++ unwind semantics
    don't work on postgres' errors. You cannot use those C++ features and
    postgres' APIs together.

    Regards,
    ---
    Takahiro Itagaki
    NTT Open Source Software Center

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-hackers @
categoriespostgresql
postedApr 2, '10 at 2:03a
activeApr 2, '10 at 5:47a
posts2
users2
websitepostgresql.org...
irc#postgresql

2 users in discussion

Takahiro Itagaki: 1 post Pei He: 1 post

People

Translate

site design / logo © 2022 Grokbase