Skip site navigation (1) Skip section navigation (2)

Re: Compilations failing

From: "Andreas Gidlund" <vaxis(at)hotmail(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Compilations failing
Date: 2006-10-01 19:36:56
Message-ID: BAY103-F396CACAB6479B0A275F31FBA1E0@phx.gbl (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
I just wanted to share my experience with other novice users as me...

For me to get it to work with first the windows installer for PostgreSQL and 
to setup a project in Visual Studio 2005 I followed this steps:

* Install PostgeSQL (obviously!)
* Add the \bin directory in the PostgreSQL root to the PATH environment 
variable (My computer -> Properties -> Advanced -> Environment variables -> 
System variables -> add the \bin directory at the end of the PATH variable. 
This way the compiled program has access to all necessary dlls.
* As the windows installer does not compile libpqdll.lib (hint at developers 
of postgres!), it has do be compiled manually. This is done by first 
downloading the source code. Thereafter run the command prompt and navigate 
to and run vsvars32.bat in the \VC\bin folder of the Visual Studio root 
installation folder.
Libpqdll.lib is compiled by compiling the whole libpq API. This is done by, 
still in the command prompt, navigating into \src\interfaces\libpq in the 
source distribution and running “nmake /f win32.mak”. Though, besides the 
numerous warnings the compiler gives while compiling, it will stop when 
compiling \src\backend\utils\mb\wchar.c, because there are two functions 
which cannot be compiled, pg_euc_mblen and pg_euc_dsplen. The reason is that 
they are declared both static and inlined, which is a syntax nmake 
appearantly does not support. It is safe to remove the inline keywords, as 
they do not change any functionality (right?!).
After recompiling with “nmake /f win32.mak” again the libpqdll.lib is 
successfully compiled and put into \src\interfaces\libpq\Release.

* In Visual Studio it is needed to do the following:
- Right-click the project -> Add -> Existing item -> browse to libpqdll.lib 
and import it. I got a warning saying there is now custom build rule for 
*.lib. Just ignore and press no.
- Right-click the project -> Properties -> Configuration properties -> C/C++ 
-> add the path to \include of the PostgreSQL root to "Additional Include 
- In the code add #include <libpq-fe.h>

With this I managed to connect to the database with:
PGconn *pgcConn;
pgcConn = PQconnectdb("dbname=postgres user=postgres password=password");

Though, here comes a problem. When I tried to execute a query and hence 
recieve the result into a PGresult, the compiler complains about that the 
variable uses an undefined struct, pg_result. I thought all the structures 
were incorporated in the libpqdll.lib file... I solved this by copying 
libpq-int.h from \src\interfaces\libpq in the source tree into \include in 
the postgres root and adding #include <libpq-int.h> into my code. But this 
also makes the libpqdll.lib obsolete, as all structure definitions can be 
found in libpq-int.h, right? And neither does it fell like the right 
approach to include libpq-int.h into the project instead of the 
libpqdll.lib, especially since it is stated in libpq-int.h that it is only 
for the frontend libpq library to include and should not be used by 
applications that call the library.

Anyone has a thought about this?

>From: "Andreas Gidlund" <vaxis(at)hotmail(dot)com>
>To: pgsql-interfaces(at)postgresql(dot)org
>Subject: Re: [INTERFACES] Compilations failing
>Date: Fri, 29 Sep 2006 14:38:43 +0200
>I am getting so frustrated here...
>As compiling with the command prompt failed so hard, I went over to compile 
>with msys and mingw and actually managed to compile postgres, but it failed 
>on compiling a dynamic library of libpxx in the next step.
>I have therefore left the ambitions to compile libpqxx for now. So I went 
>on with making a project in visual studio and the aim to use only 
>the libpq dll I managed to compile in msys. That also failed...
>So I have been searching all over the internet to find out how to use libpq 
>in VS, but with no luck at all. I am missing a short and easy to follow 
>guide. My test program only tries to create a connection object as follows:
>	PGconn *conn;
>	conn = PQconnectdb("dbname = postgres");
>I also have #include "libpq-fe.h" in the beginning. However, I get the 
>following two messages when compiling:
>error LNK2028: unresolved token (0A00000A) "extern "C" struct pg_conn * 
>__clrcall PQconnectdb(char const *)" 
>(?PQconnectdb@@$$J0YMPAUpg_conn@@PBD(at)Z) referenced in function "public: 
>__clrcall IDBConnection::claPostgreSQL::claPostgreSQL(char *)" 
>(??0claPostgreSQL(at)IDBConnection@@$$FQAM(at)PAD@Z)	claPostgreSQL.obj
>error LNK2019: unresolved external symbol "extern "C" struct pg_conn * 
>__clrcall PQconnectdb(char const *)" 
>(?PQconnectdb@@$$J0YMPAUpg_conn@@PBD(at)Z) referenced in function "public: 
>__clrcall IDBConnection::claPostgreSQL::claPostgreSQL(char *)" 
>(??0claPostgreSQL(at)IDBConnection@@$$FQAM(at)PAD@Z)	claPostgreSQL.obj
>Though, it is quite obvious it is at least because there is no reference to 
>libpq.dll. I simply don't know how to refer to that file. I also read 
>somewhere that I have to include libpqdll.lib, is that true?
>Even more spoiling my attempts is that the only compiled file for libpq I 
>get while compiling postgres through msys is the libpq.dll file. I found in 
>the documentation of 7.4.13 that libpqdll.lib and libpq.lib also should be 
>created, but they are not for me... The "make" call doesn't return any 
>errors, just that postgres is ready to be installed. Has this been changed 
>in v8 or should these files also be created there?
>Can someone please help me? I'm soon starting to cry for real...
>>From: "Jeroen T. Vermeulen" <jtv(at)xs4all(dot)nl>
>>To: "Andreas Gidlund" <vaxis(at)hotmail(dot)com>
>>CC: pgsql-interfaces(at)postgresql(dot)org
>>Subject: Re: [INTERFACES] Compilations failing
>>Date: Wed, 27 Sep 2006 10:23:41 +0700 (ICT)
>>On Wed, September 27, 2006 05:41, Andreas Gidlund wrote:
>> > I have a problem when compiling libpqxx with the tools from VS.NET 2005
>> > for use on Windows XP.
>>But the actual errors you run into happen while compiling postgres itself,
>>right?  You may want to come over the the libpqxx-general mailing list
>>(see ) for help with libpqxx-specific problems.
>> > However, after downloading libpqxx, as I wanted to compile and use it, 
>> > ran
>> > into problems. First, after having creating the common file in the 
>> > folder and when I was to change the paths inside, all three paths did 
>> > comply with my installation. First for the path to the source code, I
>> > installed by using the msi distribution and hence did not have the 
>> > at hand.
>>From what I've heard, the Windows installer doesn't install the header
>>files for libpq, and those are needed for compiling libpqxx (or any other
>>program that uses libpq).  That's why you need the postgres source
>>archive.  The paths are a painful obstacle; there just don't seem to be
>>any real standards for these things on Windows.
>>I guess there really ought to be a separate "development package" of
>>postgres for Windows like there is for other systems.  The problem seems
>>to be that Windows lacks the necessary compiler standards--a development
>>package would have to be compiler-specific.  :-(
>>You should be able to get away with compiling just the Release version of
>>libpqxx if that's what you want, using the Release version of libpq, and
>>just "stealing" the libpq headers from the postgres source tree.  But
>>chances are that you'll want to debug your software sometimes, if only
>>during development, so it's better to have both Debug and Release versions
>>of everything available.
>Börjar bilen krångla? Köp en ny
>---------------------------(end of broadcast)---------------------------
>TIP 3: Have you checked our extensive FAQ?

Prova nya Live Messenger!

In response to


pgsql-interfaces by date

Next:From: Jeroen T. VermeulenDate: 2006-10-02 06:51:38
Subject: Re: Compilations failing
Previous:From: Andreas GidlundDate: 2006-09-29 12:38:43
Subject: Re: Compilations failing

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group