LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-16-2007, 01:33 PM   #1
skie_knite007
Member
 
Registered: Dec 2004
Location: India
Distribution: Fedora Core 4
Posts: 145

Rep: Reputation: 15
Question Error in compiling Postgres FE C program


Hi folks,

I am a newbie to postgres FE programming. I am trying to connect to Postgres db like

Code:
#include <stdio.h>
#include "pgsql/libpq-fe.h"

int
main(int argc, char **argv)
{
   const char *conninfo;
        PGconn     *conn;
        PGresult   *res;
        extern PGconn *PQconnectStart(const char *conninfo);
           if (argc > 1)
                conninfo = argv[1];
        else
                conninfo = "dbname = table";

        /* Make a connection to the database */
        conn = PQconnectdb(conninfo);

        /* Check to see that the backend connection was successfully made */
        if (PQstatus(conn) != CONNECTION_OK)
        {
                fprintf(stderr, "Connection to database failed: %s",
                        PQerrorMessage(conn));
                exit_nicely(conn);
        }
I compiled it just like ordinary C pgms, using
gcc <My program.c>


All the functions like PQconnectdb() are defined in libpq-fe.h

Now my compiler is throwing error like

"
undefined reference to `PQconnectdb'

"


But this is defined in the header file.... Again I tried copying the entire header file in my program. ( All the defenitions are now in the program itself)

Again it is showing the undefined reference problem..............
What could be wrong????
please help me

Do I need to add any extra options while compiling?
 
Old 03-16-2007, 01:48 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
You need to link to the postgre libraries. Try passing the line -lpq to gcc (i.e., “gcc -lpq <My program.c>”).

Btw, your compiler is not really throwing the error, it’s the linker.
 
Old 03-16-2007, 10:38 PM   #3
skie_knite007
Member
 
Registered: Dec 2004
Location: India
Distribution: Fedora Core 4
Posts: 145

Original Poster
Rep: Reputation: 15
Thanks a lot osor. It did help..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in compiling program such as kde and sdl_image (libpng 1.2.10 from source) AleXXandEr Linux - Software 6 07-05-2006 06:52 AM
error compiling srgp program in c csst0136 Programming 10 10-25-2005 12:14 AM
error compiling srgp program in c csst0136 SUSE / openSUSE 0 10-23-2005 02:46 PM
error while compiling c /c++ program kiranbud Programming 1 10-12-2005 08:19 PM
error compiling a program minm Linux - Newbie 7 08-01-2005 10:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration