Re: [GENERAL] connecting using libpq breaks printf
Joey Morris wrote: This is my first attempt at using libpq, and I'm running across a strange problem. Here is my bare-bones program: #include stdio.h #include libpq-fe.h int main(int argc, char **argv) { PGconn *conn; fprintf(stderr, connecting\n); conn = PQconnectdb(dbname=postgres); PQfinish(conn); return 0; } I expected this program to print connecting, but in fact I get no output whatsoever. If I comment out the PQconnectdb and PQfinish lines, I see connecting as expected. What could be going on here? I tried your program, and it compiles and runs on my MinGW installation and also writes the output to stderr. One silly question first: are you sure that you actually call your executable? You didn't name it test.exe, did you? If you have problems printing to stderr, you could write to a log file: outf = fopen(logfile.txt, a); fprintf(outf, whatever); fclose(outf); or something like that. If that doesn't work, odds are good that your code is not executed at all. Yours, Laurenz Albe -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
[GENERAL] connecting using libpq breaks printf
This is my first attempt at using libpq, and I'm running across a strange problem. Here is my bare-bones program: #include stdio.h #include libpq-fe.h int main(int argc, char **argv) { PGconn *conn; fprintf(stderr, connecting\n); conn = PQconnectdb(dbname=postgres); PQfinish(conn); return 0; } I expected this program to print connecting, but in fact I get no output whatsoever. If I comment out the PQconnectdb and PQfinish lines, I see connecting as expected. What could be going on here? A few notes: - I'm running PostgreSQL 8.3.6 on Windows XP. I used the one-click installer to install. - I'm compiling the program with MinGW. I get no compiler warnings or errors. - I can connect to the database just fine using pgAdmin and the command-line client. The database is running on localhost. - I've tried adding code to see if PQstatus(conn) == CONNECTION_OK, but this hasn't been useful. Since fprintf() isn't working, I can't display a message showing the result of the comparison. - I've tried various combinations of connection options in case there was an issue with the hostname, database name, username, or password. I always get the same result: no output. - I've tried printing to stdout and to a file, but neither helped. Thanks for any help you can provide. Joey -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
[GENERAL] connecting using libpq breaks printf
This is my first attempt at using libpq, and I'm running across a strange problem. Here is my bare-bones program: #include stdio.h #include libpq-fe.h int main(int argc, char **argv) { PGconn *conn; fprintf(stderr, connecting\n); conn = PQconnectdb(dbname=postgres); PQfinish(conn); return 0; } I expected this program to print connecting, but in fact I get no output whatsoever. If I comment out the PQconnectdb and PQfinish lines, I see connecting as expected. What could be going on here? A few notes: - I'm running PostgreSQL 8.3.6 on Windows XP. I used the one-click installer to install. - I'm compiling the program with MinGW. I get no compiler warnings or errors. - I can connect to the database just fine using both pgAdmin and the command-line client. The database is running on localhost. - I've tried adding code to see if PQstatus(conn) == CONNECTION_OK, but this hasn't been useful. Since fprintf() isn't working, I can't display a message showing the result of the comparison. - I've tried various combinations of connection options in case there was an issue with the hostname, database name, username, or password. I always get the same result: no output. - I've tried printing to stdout and to a file, but neither helped. Thanks for any help you can provide. Joey -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] connecting using libpq breaks printf
This is my first attempt at using libpq, and I'm running across a strange problem. Here is my bare-bones program: #include stdio.h #include libpq-fe.h int main(int argc, char **argv) { PGconn *conn; fprintf(stderr, connecting\n); conn = PQconnectdb(dbname=postgres); PQfinish(conn); return 0; } I expected this program to print connecting, but in fact I get no output whatsoever. If I comment out the PQconnectdb and PQfinish lines, I see connecting as expected. What could be going on here? A few notes: - I'm running PostgreSQL 8.3.6 on Windows XP. I used the one-click installer to install. - I'm compiling the program with MinGW. I get no compiler warnings or errors. - I can connect to the database just fine using both pgAdmin and the command-line client. The database is running on localhost. - I've tried adding code to see if PQstatus(conn) == CONNECTION_OK, but this hasn't been useful. Since fprintf() isn't working, I can't display a message showing the result of the comparison. - I've tried various combinations of connection options in case there was an issue with the hostname, database name, username, or password. I always get the same result: no output. - I've tried printing to stdout and to a file, but neither helped. Thanks for any help you can provide. Joey try fprintf(stdout,Connection \n); printf(Connection \n); -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] connecting using libpq breaks printf
Hi, This is my first attempt at using libpq, and I'm running across a strange problem. Here is my bare-bones program: #includestdio.h #include libpq-fe.h int main(int argc, char **argv) { PGconn *conn; fprintf(stderr, connecting\n); conn = PQconnectdb(dbname=postgres); PQfinish(conn); return 0; } I expected this program to print connecting, but in fact I get no output whatsoever. If I comment out the PQconnectdb and PQfinish lines, I see connecting as expected. What could be going on here? Did you use *exactly* the same command line to compile both versions? What is that command line(s)? A few notes: - I'm running PostgreSQL 8.3.6 on Windows XP. I used the one-click installer to install. - I'm compiling the program with MinGW. I get no compiler warnings or errors. - I can connect to the database just fine using both pgAdmin and the command-line client. The database is running on localhost. - I've tried adding code to see if PQstatus(conn) == CONNECTION_OK, but this hasn't been useful. Since fprintf() isn't working, I can't display a message showing the result of the comparison. - I've tried various combinations of connection options in case there was an issue with the hostname, database name, username, or password. I always get the same result: no output. - I've tried printing to stdout and to a file, but neither helped. Thanks for any help you can provide. Joey -- Aurimas -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] connecting using libpq breaks printf
Lennin Caro lennin.c...@yahoo.com wrote on Wed, Feb 18, 2009 at 06:53:32AM -0800: try fprintf(stdout,Connection \n); printf(Connection \n); Thanks, but both produce the same behavior as fprintf(stderr, Connection \n): It prints when the PQconnectdb and PQfinish lines are commented out but not when they are present. -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] connecting using libpq breaks printf
Hi, Looks like you accidently wrote to me personnally, not to mailing list. On Wed, Feb 18, 2009 at 10:01 AM, Aurimas Černiusauri...@gmail.com wrote: Did you use *exactly* the same command line to compile both versions? What is that command line(s)? Yes, I used the same compilation command line for both versions: gcc -o pq_test -IC:\Program Files\PostgreSQL\8.3\include -LC:\Program Files\PostgreSQL\8.3\lib -lpq pq_test.c Libraries should be places after the source file, that is (not sure about -L, but for -l surely): gcc -o pq_test -IC:\Program Files\PostgreSQL\8.3\include pq_test.c -LC:\Program Files\PostgreSQL\8.3\lib -lpq I don't if that's the problem, but it's not hard to try :) -- Aurimas -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] connecting using libpq breaks printf
Aurimas Černius auri...@gmail.com wrote on Wed, Feb 18, 2009 at 06:08:07PM +0200: Libraries should be places after the source file, that is (not sure about -L, but for -l surely): gcc -o pq_test -IC:\Program Files\PostgreSQL\8.3\include pq_test.c -LC:\Program Files\PostgreSQL\8.3\lib -lpq I don't if that's the problem, but it's not hard to try :) Thanks for the suggestion, but unfortunately it didn't fix this problem. -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] connecting using libpq breaks printf
Hi, Aurimas Černiusauri...@gmail.com wrote on Wed, Feb 18, 2009 at 06:08:07PM +0200: Libraries should be places after the source file, that is (not sure about -L, but for -l surely): gcc -o pq_test -IC:\Program Files\PostgreSQL\8.3\include pq_test.c -LC:\Program Files\PostgreSQL\8.3\lib -lpq I don't if that's the problem, but it's not hard to try :) Thanks for the suggestion, but unfortunately it didn't fix this problem. How do you run the program, in console or by double clicking on executable. Try the second. Does the console window apear on the screen? -- Aurimas -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] connecting using libpq breaks printf
On Wed, Feb 18, 2009 at 9:47 AM, Joey Morris rjmorri...@gmail.com wrote: I expected this program to print connecting, but in fact I get no output whatsoever. If I comment out the PQconnectdb and PQfinish lines, I see connecting as expected. What could be going on here? Try adding fflush(stderr); after your fprintf() call. If the connection is hanging and output hasn't been flushed, you wouldn't see much. -- - David T. Wilson david.t.wil...@gmail.com -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] connecting using libpq breaks printf
David Wilson david.t.wil...@gmail.com wrote on Wed, Feb 18, 2009 at 11:36:44AM -0500: Try adding fflush(stderr); after your fprintf() call. If the connection is hanging and output hasn't been flushed, you wouldn't see much. No, this doesn't help, either. Thanks for the suggestion. -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] connecting using libpq breaks printf
On Wed, Feb 18, 2009 at 06:08:07PM +0200, Aurimas Cernius wrote: Joey Morris wrote: gcc -o pq_test -IC:\Program Files\PostgreSQL\8.3\include -LC:\Program Files\PostgreSQL\8.3\lib -lpq pq_test.c gcc won't give many warnings unless you give it a -Wall flag; it may be doing strange things and not telling you, doubt it though the code looks nice and simple and compiles and runs here OK. I'm running on a Linux box though, but that shouldn't matter for this code. Have you got a debugger available, it could help to single step through and see what's going on. Just thought, it's not because it can't find the DLL is it? -- Sam http://samason.me.uk/ -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] connecting using libpq breaks printf
On Wed, Feb 18, 2009 at 4:47 PM, Joey Morris rjmorri...@gmail.com wrote: This is my first attempt at using libpq, and I'm running across a strange problem. Here is my bare-bones program: #include stdio.h #include libpq-fe.h int main(int argc, char **argv) { PGconn *conn; fprintf(stderr, connecting\n); conn = PQconnectdb(dbname=postgres); PQfinish(conn); return 0; } Works fine with linux + gcc. Must be something in your environment. Regards Mikko
Re: [GENERAL] connecting using libpq breaks printf
How do you run the program, in console or by double clicking on executable. Try the second. Does the console window apear on the screen? Aha! This tip has led to the solution. I had been running the program from an emacs shell buffer. If I run it from the Windows console or by double-clicking the executable, a dialog box pops up with this error message: The application has failed to start because LIBPQ.dll was not found. Re-installing the application may fix this problem. At run-time, the system apparently cannot find libpq.dll and is aborting immediately. The reason is that the directory containing libpq.dll was not in my DLL search path. I added C:\Program Files\PostgreSQL\8.3\bin to my PATH environment variable, and now the program works as expected. Note that adding C:\Program Files\PostgreSQL\8.3\lib to the PATH doesn't completely solve the problem, since bin contains some necessary DLLs that aren't in lib (such as ssleay32.dll). Alternatively, I could have copied the DLLs to C:\Windows\system32 or to the directory containing the executable, but I like the PATH solution better. Thanks, everyone, for your help! -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] connecting using libpq breaks printf
Aurimas Černius auri...@gmail.com wrote on Wed, Feb 18, 2009 at 05:01:14PM +0200: Did you use *exactly* the same command line to compile both versions? What is that command line(s)? Yes, I used the same compilation command line for both versions: gcc -o pq_test -IC:\Program Files\PostgreSQL\8.3\include -LC:\Program Files\PostgreSQL\8.3\lib -lpq pq_test.c -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general