Why do I get compilation errors when trying to connect to postgresql with c? - postgresql

I tried to create a simple c programm which should connect to my postgres db, but I am not able to get aware of the following compilation errors...
I am using Ubuntu (but also tried to compile on Fedora already - with the same errors...)
uname --all
Linux alp2nwmon001 2.6.35-25-server #44-Ubuntu SMP Fri Jan 21 19:09:14 UTC 2011 x86_64 GNU/Linux
I installed postgres inclusive libpq-dev libpq5 libs already and I have no clue why this simple code is not working...
#include "/usr/include/postgresql/libpq-fe.h"
int main () {
PGConn *test;
return 0;
}
I also tried lots of variations like: #include <libpq-fe.h>, and specify the path to the .h file when calling gcc.
But always the same errors...
gcc -c -I/usr/include/postgresql/ -L/usr/lib/ -lpq pqtest.c -o postgres
pqtest.c: In function main:
pqtest.c:4: error: PGConn undeclared (first use in this function)
pqtest.c:4: error: (Each undeclared identifier is reported only once
pqtest.c:4: error: for each function it appears in.)
pqtest.c:4: error: test undeclared (first use in this function)
Further I found a lot of howtos, but still the same result:
http://www.mkyong.com/database/how-to-building-postgresql-libpq-programs/
http://forum.ubuntu-fr.org/viewtopic.php?pid=3212499
I also checked the API description at the postgres webpage, still no luck.
In my opinion all files exist where the should exist...
ls -lah /usr/include/postgresql/libpq-fe.h
-rw-r--r-- 1 root root 20K 2011-04-20 16:36 /usr/include/postgresql/libpq-fe.h
And the libraries...
ls /usr/lib/ | grep pq
libpq.a
libpq.so
libpq.so.5
libpq.so.5.2
libpqxx-2.6.9.so
libpqxx.la
libpqxx.so
I hope somebody can help me here...
Thx br,
roegi

Use PGconn instead of PGConn.

Related

Error in ./configure step in installation of libpqxx

this is a bit of a long shot but:
I'm following this guide: https://www.tutorialspoint.com/postgresql/postgresql_c_cpp.htm
But when running ./configure I get the following error:
(previous checking lines omitted for brevity)
checking for main in -lpq... yes
checking for PQexec in -lpq... yes
checking for correct C++ linkage of basic libpq functions...
sed: character class syntax is [[:space:]], not [:space:]
configure: error:
Linking a call to libpq failed in C++, even though it succeeded in C. If your
C and C++ compilers are very different beasts, this may mean that we do not have
the right options for linking with it after all.
Read the config.log file for more detailed information. Look for the last error
message, which may be several pages up from the end of the file.
And the configure.log file looks like this:
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by libpqxx configure 4.0, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ ./configure
## --------- ##
## Platform. ##
## --------- ##
(some lines omitted)
configure:3039: g++ -V >&5
g++: error: unrecognized command line option '-V'
g++: fatal error: no input files
compilation terminated.
configure:3050: $? = 1
configure:3039: g++ -qversion >&5
g++: error: unrecognized command line option '-qversion'; did you mean '--version'?
g++: fatal error: no input files
compilation terminated.
(some lines omitted)
configure:7629: gcc -E conftest.c
conftest.c:11:10: fatal error: ac_nonexistent.h: No such file or directory
#include <ac_nonexistent.h>
^~~~~~~~~~~~~~~~~~
compilation terminated.
(some lines omitted)
configure:8319: gcc -c -g -O2 -fno-rtti -fno-exceptions conftest.c >&5
cc1: warning: command line option '-fno-rtti' is valid for C++/ObjC++ but not for C
(some lines omitted)
configure:16424: g++ -o conftest -g -O2 -L/usr/lib/x86_64-linux-gnu conftest.cpp >&5
/tmp/ccfFBf4K.o: In function `main':
/home/peter/libpqxx-4.0/conftest.cpp:44: undefined reference to `PQexec'
collect2: error: ld returned 1 exit status
(some liens omitted)
I don't believe I have any packages missing. I have the newest version of g++, psql and libpqxx installed.
I have updated and upgraded all packages on my system.
I have crawled the web for solutions to this error, but I have no clue what is wrong.
Do you have an idea where I can go from here?
There hasn't been a tarball release of libpqxx at the old spot in a long time, so the tutorial you used with its wget command to download the tarball is very outdated.
The issue you encountered looks related to this issue and appears to have been fixed in this commit:
commit 85e9336740475be25ed19924cca0961f7d844c4b
Author: Jeroen Vermeulen <jtvjtv#gmail.com>
Date: Thu Jun 1 11:39:08 2017 +0700
Fix #13: not linking to libpq.
This was that annoying interaction between autoconf, m4, GNU sed syntax,
and the shell which broke the "remove redundant -lpq options" code in
the configure script.
Solution: forget about GNU sed's "[[:space:]]" syntax, and just look for
a literal space. There aren't going to be any tabs, newlines,
non-breaking spaces, etc. there in even a moderately sane world.

Compiling Net::SSL for Strawberry Perl: “openssl/ssl.h: No such file or directory”

When I try to install Net::SSL I get the following output. I don't understad it at all. Can anyone point me in the right direction, without getting to techy?
C:\Documents and Settings\Administrator>cpan
CPAN: File::HomeDir loaded ok (v0.69)
cpan shell -- CPAN exploration and modules installation (v1.9205)
ReadLine support enabled
cpan> install Net::SSL
Database was generated on Tue, 14 Aug 2012 14:54:56 GMT
Running install for module 'Net::SSL'
Running make for N/NA/NANIS/Crypt-SSLeay-0.64.tar.gz
Checksum for C:\strawberry\cpan\sources\authors\id\N\NA\NANIS\Crypt-SSLeay-0.64.
tar.gz ok
Scanning cache C:\strawberry\cpan\build for sizes
............................................................................DONE
CPAN.pm: Going to build N/NA/NANIS/Crypt-SSLeay-0.64.tar.gz
The test suite can attempt to connect to public servers to ensure that the
code is working properly. If you are behind a strict firewall or have no
network connectivity, these tests may fail (through no fault of the code).
Do you want to run the live tests (y/N)? [N]
WARNING: BUILD_REQUIRES is not a known parameter.
Checking if your kit is complete...
Looks good
Warning: prerequisite LWP::Protocol::https 6.02 not found.
'BUILD_REQUIRES' is not a known MakeMaker parameter name.
Writing Makefile for Crypt::SSLeay
cp lib/Crypt/SSLeay/X509.pm blib\lib\Crypt\SSLeay\X509.pm
cp lib/Net/SSL.pm blib\lib\Net\SSL.pm
cp SSLeay.pm blib\lib\Crypt\SSLeay.pm
cp lib/Crypt/SSLeay/Conn.pm blib\lib\Crypt\SSLeay\Conn.pm
cp lib/Crypt/SSLeay/CTX.pm blib\lib\Crypt\SSLeay\CTX.pm
cp lib/Crypt/SSLeay/MainContext.pm blib\lib\Crypt\SSLeay\MainContext.pm
cp lib/Crypt/SSLeay/Err.pm blib\lib\Crypt\SSLeay\Err.pm
C:\strawberry\perl\bin\perl.exe C:\strawberry\perl\lib\ExtUtils\xsubpp -typemap
C:\strawberry\perl\lib\ExtUtils\typemap -typemap typemap SSLeay.xs > SSLeay.xs
c && C:\strawberry\perl\bin\perl.exe -MExtUtils::Command -e mv SSLeay.xsc SSLeay
.c
gcc -c -IC:\strawberry\c\include -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DPERL_
IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -DPERL_MSVCRT_READFIX
-s -O2 -DVERSION=\"0.64\" -DXS_VERSION=\"0.64\" "-IC:\strawberry\perl\lib
\CORE" SSLeay.c
SSLeay.xs:35:25: openssl/ssl.h: No such file or directory
SSLeay.xs:36:28: openssl/crypto.h: No such file or directory
SSLeay.xs:37:25: openssl/err.h: No such file or directory
SSLeay.xs:38:26: openssl/rand.h: No such file or directory
SSLeay.xs:39:28: openssl/pkcs12.h: No such file or directory
SSLeay.xs:55: error: syntax error before '*' token
SSLeay.xs: In function `InfoCallback':
SSLeay.xs:60: error: `where' undeclared (first use in this function)
SSLeay.xs:60: error: (Each undeclared identifier is reported only once
SSLeay.xs:60: error: for each function it appears in.)
SSLeay.xs:60: error: `SSL_ST_MASK' undeclared (first use in this function)
SSLeay.xs:62: error: `SSL_ST_CONNECT' undeclared (first use in this function)
SSLeay.xs:64: error: `SSL_ST_ACCEPT' undeclared (first use in this function)
SSLeay.xs:69: error: `SSL_CB_LOOP' undeclared (first use in this function)
SSLeay.xs:70: error: `s' undeclared (first use in this function)
SSLeay.xs:72: error: `SSL_CB_ALERT' undeclared (first use in this function)
SSLeay.xs:73: error: `SSL_CB_READ' undeclared (first use in this function)
SSLeay.xs:75: error: `ret' undeclared (first use in this function)
SSLeay.xs:78: error: `SSL_CB_EXIT' undeclared (first use in this function)
SSLeay.c: In function `XS_Crypt__SSLeay__CTX_new':
SSLeay.c:146: error: `SSL_CTX' undeclared (first use in this function)
SSLeay.c: In function `XS_Crypt__SSLeay__CTX_use_pkcs12_file':
SSLeay.c:334: error: `SSL_CTX' undeclared (first use in this function)
SSLeay.c:334: error: `ctx' undeclared (first use in this function)
SSLeay.xs:188: error: `EVP_PKEY' undeclared (first use in this function)
SSLeay.xs:188: error: `pkey' undeclared (first use in this function)
SSLeay.c:421: error: `ctx' undeclared (first use in this function)
SSLeay.c:646: error: `ssl' undeclared (first use in this function)
SSLeay.c:658: error: syntax error before ')' token
LOTS OF LINES SIMILAR TO ABOVE
SSLeay.xs:505: error: invalid type argument of `->'
dmake.EXE: Error code 129, while making 'SSLeay.o'
NANIS/Crypt-SSLeay-0.64.tar.gz
C:\strawberry\c\bin\dmake.EXE -- NOT OK
Running make test
Can't test without successful make
Running make install
Make had returned bad status, install seems impossible
Failed during this command:
NANIS/Crypt-SSLeay-0.64.tar.gz : make NO
I had the same problem and, although I had the openSSL package installed, the development headers where not. I had to install the package libssl-dev. I used the Ubuntu Software Center to download and install the package. Alternately, you could use sudo apt-get install libssl-dev from the terminal command line.
That fixed my problem but is no real help to you working with windows. openSSL has a link to a binary for windows at: OpenSSL for Windows
The following lines suggest that you probably have not installed the OpenSSL library/headers or it is in a location not known to perl. Install it with the package manager of your operating system, or compile and install it.
>SSLeay.xs:35:25: openssl/ssl.h: No such file or directory
>SSLeay.xs:36:28: openssl/crypto.h: No such file or directory
>SSLeay.xs:37:25: openssl/err.h: No such file or directory
>SSLeay.xs:38:26: openssl/rand.h: No such file or directory
>SSLeay.xs:39:28: openssl/pkcs12.h: No such file or directory
After installing the library/headers, cpan should be able to make and install Net::SSL.
Generally CPAN takes care of this for you by installing all the dependent modules.
The problem you are facing is with this warning
WARNING: BUILD_REQUIRES is not a known parameter.
Now since CPAN is unable to read this parameter it is unable to get all the dependent modules for you and hence is unable to install.
The Problem may be with the perl-ExtUtils-MakeMaker module with comes with cpan utility.
You may want to install the latest version of cpan and try. Or as previously mentioned You may want to install all the modules after downloading them individually and then installing them manually.
First, I have got the problem like this:
mod_qos.c:83:26: error: openssl/rand.h: No such file or directory
mod_qos.c:84:25: error: openssl/evp.h: No such file or directory
Then I used the following:
apxs -I/usr/local/openssl/include/openssl -i -c mod_qos.c -lcrypto -lpcre
and it succeeded! Why?

Error in ./configure in solaris 11

Okay i am trying to install BIND on solaris 11.
Upon downloading the tar file using wget, then i used extract it out.
After which, when i enter the command :
./configure
i face the following error
checking <<some stuff>>
..
..
..
checking <<some stuff>>
checking whether we are cross compiling... configure: error: in '/home/user/user/downloads/bind9.8.2
configure: error: cannot run C compiled programs.
If you meant to cross compile, use '--host'.
so i used --host in my option, but i cant get it to work,
For example, i entered the below command :
./configure --host=ulinux-uclibc
I received an error saying
checking host system type... Invalid configuration 'ulinux-uclibc': machine 'ulinux' not recognized
Thanks! :)
Why not just install the bind package from your configured solaris publisher?
# pkg install network/dns/bind service/network/dns/bind
should get you exactly what you need. That will get you ISC Bind v9.6.3 if you use pkg.oracle.com/solaris/release publisher.

PJSIP compilation for iphone simulator

I am trying to compile pjsip for iphone simulator and getting the error:
../include/pj/config_site_sample.h:322:1: warning: this is the location of the previous definition
../src/pj/activesock.c: In function ‘activesock_create_iphone_os_stream’:
../src/pj/activesock.c:146: error: ‘kCFStreamNetworkServiceType’ is unavailable (declared at /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/System/Library/Frameworks/CFNetwork.framework/Headers/CFSocketStream.h:256)
../src/pj/activesock.c:147: error: ‘kCFStreamNetworkServiceTypeVoIP’ is unavailable (declared at /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/System/Library/Frameworks/CFNetwork.framework/Headers/CFSocketStream.h:259)
Please help.
for the benefit of others: used the latest pjsip from trunk.
change the below line to i686 in configure_iphone
for archpath in `ls -d ${SDKPATH}/usr/lib/gcc/arm-apple-darwin*`; do
to
for archpath in `ls -d ${SDKPATH}/usr/lib/gcc/i686-apple-darwin*`; do
and create config_site.h (pjlib/include/pj) with below lines
#define PJ_CONFIG_IPHONE 1
#include <pj/config_site_sample.h>
make sure you have correct sdk and arch settings. I used the ones below.
export CFLAGS="-O2 -m32 -miphoneos-version-min=4.0" LDFLAGS="-O2 -m32"
export IPHONESDK=iPhoneSimulator4.2.sdk
export DEVPATH=/Developer/Platforms/iPhoneSimulator.platform/Developer
export ARCH="-arch i686"
Also it is weird that build/rules.mak has invalid spaces instead of tabs (check last few lines). replace the spaces with tabs and do
$ rm pjlib/build/.pjlib*
$ rm pjnath/build/.pjnath*
Now finally i got it compiled.

Compiling Ncurses on Solaris - "Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications"?

I'm trying to compile a GNU stack on Solaris 10 (x86).
I've managed to get the following up so far:
GMP
MPFR
MPC
GCC
binutils
libiconv
gettext
I'm currently trying to build Ncurses, and I'm hitting an error:
/db/pub/eq/tools/bin/g++ -I../c++ -I../include -I/db/pub/eq/src/ncurses-5.9/c++ -DHAVE_CONFIG_H -D__EXTENSIONS__ -D_XOPEN_SOURCE=500 -D_FILE_OFFSET_BITS=64 -DNDEBUG -I. -I../include -I/db/pub/eq/src/ncurses-5.9/c++/../include -I/db/pub/eq/tools/include/ncurses -O2 -c /db/pub/eq/src/ncurses-5.9/c++/cursesf.cc -o ../objects/cursesf.o
<command-line>:0:0: warning: "_XOPEN_SOURCE" redefined [enabled by default]
<built-in>:0:0: note: this is the location of the previous definition
In file included from /usr/include/iso/stdlib_iso.h:30:0,
from /usr/include/stdlib.h:18,
from /db/pub/eq/src/ncurses-5.9/c++/internal.h:53,
from /db/pub/eq/src/ncurses-5.9/c++/cursesf.cc:34:
/db/pub/eq/tools/lib/gcc/i386-pc-solaris2.10/4.6.1/include-fixed/sys/feature_tests.h:341:2: error: #error "Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications"
*** Error code 1
make: Fatal error: Command failed for target `../objects/cursesf.o'
Current working directory /db/pub/eq/src/ncurses-5.9/c++
*** Error code 1
make: Fatal error: Command failed for target `all'
I'm not quite sure what the above error (Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications) means, or how to troubleshoot it.
I saw this error once before when I was building MPC (during gmake check), but I had no idea what it meant then, or how to fix it - but since it was in checks, it was ok.
Cheers,
Victor
apply this patch to the configure script:
--- configure.orig Fri Aug 5 14:28:28 2011
+++ configure Fri Aug 5 14:31:11 2011
## -7246,7 +7246,7 ##
# setting _XOPEN_SOURCE breaks Lynx on SCO Unix / OpenServer
;;
solaris2.1[0-9]) #(vi
- cf_xopen_source="-D__EXTENSIONS__ -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
+ cf_xopen_source="-D__EXTENSIONS__"
;;
solaris2.[1-9]) #(vi
cf_xopen_source="-D__EXTENSIONS__"
Ncurses 5.6 did not define _XOPEN_SOURCE for solaris either.
Cheers