Обсуждение: Compiling extension C with MingW in windows, Error...

Поиск
Список
Период
Сортировка

Compiling extension C with MingW in windows, Error...

От
Edwin Quijada
Дата:
Hi, I am tryng to compile a C extension in windows using Minigw but always I get the same error

C:\Program Files\PostgreSQL\8.3\share\exte_c>C:\mingw\bin\gcc -shared -o pg2.dll
 pg2.o
pg2.o:pg2.c:(.text+0x86): undefined reference to `_imp__CurrentMemoryContext'
pg2.o:pg2.c:(.text+0x92): undefined reference to `MemoryContextAlloc'
collect2: ld returned 1 exit status

This error is just when it links.

Aparently this occur just when use text vardata

This is the code for my function. This function was taken from manual page but it doesnt work neither.

#include <string.h>
#include "fmgr.h"

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif


PG_FUNCTION_INFO_V1(concat_text);

Datum
concat_text(PG_FUNCTION_ARGS)
{
    text  *arg1 = PG_GETARG_TEXT_P(0);
    text  *arg2 = PG_GETARG_TEXT_P(1);
    int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
   
    text *new_text = (text *) palloc(new_text_size);

    VARATT_SIZEP(new_text) = new_text_size;
   //
    memcpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1)-VARHDRSZ);
    memcpy(VARDATA(new_text) + (VARSIZE(arg1)-VARHDRSZ),
   //
   VARDATA(arg2), VARSIZE(arg2)-VARHDRSZ);
    PG_RETURN_TEXT_P(new_text);
}

Any clues about this ???

*-------------------------------------------------------*
*-Edwin Quijada
*-Developer DataBase
*-JQ Microsistemas
*-Soporte PostgreSQL
*-www.jqmicrosistemas.com
*-809-849-8087
*-------------------------------------------------------*



Re: Compiling extension C with MingW in windows, Error...

От
Magnus Hagander
Дата:
On Fri, Sep 3, 2010 at 5:31 AM, Edwin Quijada
<listas_quijada@hotmail.com> wrote:
> Hi, I am tryng to compile a C extension in windows using Minigw but always I
> get the same error
>
> C:\Program Files\PostgreSQL\8.3\share\exte_c>C:\mingw\bin\gcc -shared -o
> pg2.dll
>  pg2.o
> pg2.o:pg2.c:(.text+0x86): undefined reference to
> `_imp__CurrentMemoryContext'
> pg2.o:pg2.c:(.text+0x92): undefined reference to `MemoryContextAlloc'
> collect2: ld returned 1 exit status
>
> This error is just when it links.

You need to link against postgres.exe to get access to these symbols.
I don't recall if the mingw linker allows you to just specify the EXE
file these days, but I think it does. If not, you'll need to create an
import library from the EXE and link to that (the binary distribution
only ships with import libraries for MSVC, but mingw can't use
standard windows import libraries, so you need to create your own
there)


--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

Re: Compiling extension C with MingW in windows, Error...

От
Edwin Quijada
Дата:





> Date: Fri, 3 Sep 2010 09:41:17 +0200
> Subject: Re: [GENERAL] Compiling extension C with MingW in windows, Error...
> From: magnus@hagander.net
> To: listas_quijada@hotmail.com
> CC: pgsql-general@postgresql.org
>
> On Fri, Sep 3, 2010 at 5:31 AM, Edwin Quijada
> <listas_quijada@hotmail.com> wrote:
> > Hi, I am tryng to compile a C extension in windows using Minigw but always I
> > get the same error
> >
> > C:\Program Files\PostgreSQL\8.3\share\exte_c>C:\mingw\bin\gcc -shared -o
> > pg2.dll
> >  pg2.o
> > pg2.o:pg2.c:(.text+0x86): undefined reference to
> > `_imp__CurrentMemoryContext'
> > pg2.o:pg2.c:(.text+0x92): undefined reference to `MemoryContextAlloc'
> > collect2: ld returned 1 exit status
> >
> > This error is just when it links.
>
> You need to link against postgres.exe to get access to these symbols.
> I don't recall if the mingw linker allows you to just specify the EXE
> file these days, but I think it does. If not, you'll need to create an
> import library from the EXE and link to that (the binary distribution
> only ships with import libraries for MSVC, but mingw can't use
> standard windows import libraries, so you need to create your own
> there)

Magnus how can I linking against postgres.exe I mean the gcc line. I did others function and worked fine

This is the function that I did and worked, with this code I did a foo.dll and added this to postgresql.

#include "postgres.h"
    #include <string.h>
    #include "fmgr.h"
   
    #ifdef PG_MODULE_MAGIC
    PG_MODULE_MAGIC;
    #endif
   
    /* 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);
    }




*-------------------------------------------------------*
*-Edwin Quijada
*-Developer DataBase
*-JQ Microsistemas
*-Soporte PostgreSQL
*-www.jqmicrosistemas.com
*-809-849-8087
*-------------------------------------------------------*


Re: Compiling extension C with MingW in windows, Error...

От
Magnus Hagander
Дата:
On Fri, Sep 3, 2010 at 18:23, Edwin Quijada <listas_quijada@hotmail.com> wrote:
>
>> Date: Fri, 3 Sep 2010 09:41:17 +0200
>> Subject: Re: [GENERAL] Compiling extension C with MingW in windows,
>> Error...
>> From: magnus@hagander.net
>> To: listas_quijada@hotmail.com
>> CC: pgsql-general@postgresql.org
>>
>> On Fri, Sep 3, 2010 at 5:31 AM, Edwin Quijada
>> <listas_quijada@hotmail.com> wrote:
>> > Hi, I am tryng to compile a C extension in windows using Minigw but
>> > always I
>> > get the same error
>> >
>> > C:\Program Files\PostgreSQL\8.3\share\exte_c>C:\mingw\bin\gcc -shared -o
>> > pg2.dll
>> >  pg2.o
>> > pg2.o:pg2.c:(.text+0x86): undefined reference to
>> > `_imp__CurrentMemoryContext'
>> > pg2.o:pg2.c:(.text+0x92): undefined reference to `MemoryContextAlloc'
>> > collect2: ld returned 1 exit status
>> >
>> > This error is just when it links.
>>
>> You need to link against postgres.exe to get access to these symbols.
>> I don't recall if the mingw linker allows you to just specify the EXE
>> file these days, but I think it does. If not, you'll need to create an
>> import library from the EXE and link to that (the binary distribution
>> only ships with import libraries for MSVC, but mingw can't use
>> standard windows import libraries, so you need to create your own
>> there)
>
> Magnus how can I linking against postgres.exe I mean the gcc line. I did
> others function and worked fine

Sorry, I don't know this. I don't use mingw myself anymore. But it
should work in the same way as you link against any other third-party
DLLs with it - DLLs and EXEs are actually the same thing, just with
different names...


--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/