Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In postgresql source code there is a file called postgres.c precisely in /src/backend/tcop/. Inside there is a function called exec_simple_query. I want add a line that call my_function that is in another file called test.c in the same folder of postgres.c .

I'm working with eclipse on linux (kubuntu/ubuntu). I followed this tutorial to creating the environment

This is test.c:

#include "postgres.h"


/* interfaces */
extern void start_create_profile(List *querytree_list);
extern void create_profile();
extern void check_anomaly(List *querytree_list);

#endif /* Test ProgProf */

void start_create_profile(List *querytree_list){

    ListCell *l;
    ListCell *tl;
    FILE *f;

    //if the file exist just open and write
    //else create and write
    f = fopen ("QueryParsed.txt", "a+");

    Query *query_idr = (Query *)linitial(querytree_list);

    switch (query_idr->commandType)
        case CMD_SELECT:
            fputs("CMD_SELECT, ", f);

        case CMD_INSERT:
            fputs("CMD_INSERT, ", f);

        case CMD_UPDATE:
            fputs("CMD_UPDATE, ", f);


    //to have the ID of the table
    foreach(l, query_idr->rtable){
        Oid tab_idT = ((RangeTblEntry *) lfirst(l)) ->relid;
        //char temp1[10];
        char *tab_idTConverted = itoa(tab_idT);
        /* This is not a table */
        if (tab_idT == 0)

        fputs(" tab_id:  , ", f);
        fputs(tab_idTConverted, f);


    //to have the name of the targer list
    foreach(tl, query_idr->targetList){
        TargetEntry *tle = (TargetEntry *) lfirst(tl);
        Oid tab_id = tle->resorigtbl;
        int tab_idCast=(int)tab_id;
        //char temp[10];
        char *tab_idConverted = itoa(tab_idCast);
        char *resname=tle->resname;

        fputs("Name of column:  ", f);
        fputs(resname, f);
        fputs(" ID:  ", f);
        fputs(tab_idConverted, f);
        fputs("\n", f);

    //close the file that we write
    fputs("$", f);
    fclose (f);

void create_profile(){


void check_anomaly(List *querytree_list){


But, when I click on build I get this error:

Description Path    Resource    Location    Type
make: *** [all] Error 2     pgsql       C/C++ Problem
make[1]: *** [all] Error 2      pgsql       C/C++ Problem
make[2]: *** [postgres] Error 1     pgsql       C/C++ Problem
undefined reference to `start_create_profile'   /pgsql/src/backend/tcop postgres.c      C/C++ Problem

I don't think that is related to postgresql, but I think it is a problem of extension programming.

share|improve this question

I've solved the problem adding test.o in OBJECT in the makefile in src/backend/tcop.

An istance can be

subdir = src/backend/tcop
top_builddir = ../../..
include $(top_builddir)/src/

OBJS= dest.o fastpath.o postgres.o pquery.o utility.o test.o

ifneq (,$(filter $(PORTNAME),cygwin win32))

include $(top_srcdir)/src/backend/
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.