Building SPI programs

Started by Aristide Aragonabout 25 years ago4 messagesgeneral
Jump to latest
#1Aristide Aragon
zuri@busa.lionking.org

Hello
I have to do some programming in C or C++ and PostgreSQL.
Having not ever done this before, I opened the documentation (in my machine, /usr/local/pgsql/doc) and read about the options I had. SPI, libpq, libpq++ and ecpg. I don't want, if possible, an embeded language, or anything that requires a preprocessor. So, I thought to start by trying the first, SPI, which also seemed to be simple.
My problem comes when compiling, since the documentation doesn't say where the include files are, nor what libraries to compile against.
So, I found out about the include dirs required (amazingly, one was in the source directory tree, and was not copied to usr/local/pgsql/include when I installed PGSQL), and ended with cc -I/busa/tmp/postgresql-7.0.2/src/include/ -I/usr/local/pgsql/include test.c -o test
With this command line, I got

/tmp/ccPIp24d.o: In function `main':
/tmp/ccPIp24d.o(.text+0x7): undefined reference to `SPI_connect'
/tmp/ccPIp24d.o(.text+0x2b): undefined reference to `SPI_exec'
/tmp/ccPIp24d.o(.text+0x33): undefined reference to `SPI_finish'

So I supposed I needed to link against some library. With grep I searched /usr/local/pgsql/lib for SPI_, and I found no .a's matching.
I found that /usr/local/pgsql/lib/plpgsql.so and /usr/local/pgsql/lib/pltcl.so had "SPI_", however none worked.

So, can somebody help me compile a C program with SPI?

Thanks

Aristide

#2Ian Lance Taylor
ian@airs.com
In reply to: Aristide Aragon (#1)
Re: Building SPI programs

Aristide Aragon <zuri@busa.lionking.org> writes:

I have to do some programming in C or C++ and PostgreSQL.
Having not ever done this before, I opened the documentation (in my machine, /usr/local/pgsql/doc) and read about the options I had. SPI, libpq, libpq++ and ecpg. I don't want, if possible, an embeded language, or anything that requires a preprocessor. So, I thought to start by trying the first, SPI, which also seemed to be simple.

SPI is only for stored procedures which are dynamically linked into
the Postgres backend.

Ordinary code doesn't do that. It uses some one of the other
mechanisms.

Ian

/tmp/ccPIp24d.o(.text+0x7): undefined reference to `SPI_connect'
/tmp/ccPIp24d.o(.text+0x2b): undefined reference to `SPI_exec'
/tmp/ccPIp24d.o(.text+0x33): undefined reference to `SPI_finish'

When your program is dynamically linked in, those functions will be
satisfied by definitions in the Postgres backend.

So I supposed I needed to link against some library. With grep I searched /usr/local/pgsql/lib for SPI_, and I found no .a's matching.
I found that /usr/local/pgsql/lib/plpgsql.so and /usr/local/pgsql/lib/pltcl.so had "SPI_", however none worked.

Those are examples of backend procedures which are dynamically linked
in, in those cases to define a language.

Ian

#3Aristide Aragon
aristide@lionking.org
In reply to: Ian Lance Taylor (#2)
Re: Building SPI programs

On Thu, Feb 22, 2001 at 07:49:56PM -0800, Ian Lance Taylor wrote:

Aristide Aragon <zuri@busa.lionking.org> writes:

I have to do some programming in C or C++ and PostgreSQL.

SPI is only for stored procedures which are dynamically linked into
the Postgres backend.

Ordinary code doesn't do that. It uses some one of the other
mechanisms.

Ian

I don't understand.. So I shouldn't use SPI? If I should, how would I comple a program, if not, what can I use? Can you help me?

Thanks in advance

Aristide

Show quoted text

/tmp/ccPIp24d.o(.text+0x7): undefined reference to `SPI_connect'
/tmp/ccPIp24d.o(.text+0x2b): undefined reference to `SPI_exec'
/tmp/ccPIp24d.o(.text+0x33): undefined reference to `SPI_finish'

When your program is dynamically linked in, those functions will be
satisfied by definitions in the Postgres backend.

So I supposed I needed to link against some library. With grep I searched /usr/local/pgsql/lib for SPI_, and I found no .a's matching.
I found that /usr/local/pgsql/lib/plpgsql.so and /usr/local/pgsql/lib/pltcl.so had "SPI_", however none worked.

Those are examples of backend procedures which are dynamically linked
in, in those cases to define a language.

Ian

#4Ian Lance Taylor
ian@airs.com
In reply to: Aristide Aragon (#1)
Re: Building SPI programs

Aristide Aragon <aristide@lionking.org> writes:

On Thu, Feb 22, 2001 at 07:49:56PM -0800, Ian Lance Taylor wrote:

Aristide Aragon <zuri@busa.lionking.org> writes:

I have to do some programming in C or C++ and PostgreSQL.

SPI is only for stored procedures which are dynamically linked into
the Postgres backend.

Ordinary code doesn't do that. It uses some one of the other
mechanisms.

I don't understand.. So I shouldn't use SPI? If I should, how would I comple a program, if not, what can I use? Can you help me?

You didn't really say what you wanted to do, so I don't know whether
you should use SPI or not.

If you don't have a clue what I was talking about in my previous
message, then you should not use SPI. You should probably use the
libpq interface.

Ian