0

I have installed postgresql in my ubuntu 14.04 with apt-get command..
postgresql 9.4
libpg 9.4.8

I want to add a user defined c function for dynamic loading.
I have my c file and sql function file ready as per specification but main problem is that c file contain header lines like..


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

i have my folder on Desktop but there is no postgers.h or fmgr.h file..
I dont know where to find source file on my system but i have downloaded whole source from git and added in same folder..
If i run compiling command it shows

postgres_ext.h:47:9: error: unknown type name 'PG_INT64_TYPE'<br>
 typedef PG_INT64_TYPE pg_int64;



i dont know where to start.. should i place my file in any postgres directory and then compile or downloading the source file is right option? What to do with the error..? Please help.. Many thanks in advance.

rohan dhama
  • 56
  • 2
  • 10

1 Answers1

1

Use PGXS to compile your code as an extension by writing a simple Makefile.

This will set up the include path, library path, etc for you and supply the correct compiler flags.

It's discussed in the same documentation as the tutorials that cover writing basic C functions.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • Thanks for your answer sir.. tried the same.. got following error.. /usr/src/postgres-master/src/include/postgres_ext.h:47:9: error: unknown type name ‘PG_INT64_TYPE’ – rohan dhama Jun 12 '17 at 08:43
  • /usr/src/postgres-master/src/include/c.h:66:72: fatal error: pg_config_os.h: No such file or directory compilation terminated. – rohan dhama Jun 12 '17 at 08:52
  • Without seeing what exactly you did and how you installed, hard to say what's going on. At a wild guess you need to install the postgresql devel package for your OS/distro. – Craig Ringer Jun 13 '17 at 05:25
  • After lot of configuration i'm able to generate .so file.. my .so file is pgafis.so.. uploaded file in lib directory and uploaded .control and .sql and unpacked.sql file in appropriate directory.. when i run CREATE EXTENSION pgafis in my pgadmin-III i receive.. ERROR: could not load library "/usr/lib/postgresql/9.4/lib/pgafis.so": /usr/lib/postgresql/9.4/lib/pgafis.so: undefined symbol: lfsparms_V2 SQL state: XX000 Can u please help? – rohan dhama Jun 14 '17 at 06:45
  • New question please. Link back to this for context. – Craig Ringer Jun 14 '17 at 10:33
  • https://stackoverflow.com/questions/44551517/error-could-not-load-library-pgafis-so-undefined-symbol-lfsparms-v2 – rohan dhama Jun 14 '17 at 17:52