Ticket #144 (new defect)

Opened 6 months ago

Last modified 3 weeks ago

Compile libpqxx Windows platform SDK AMD64

Reported by: anonymous Assigned to:
Priority: highest Milestone:
Component: portability Version: 2.6
Severity: critical Keywords:
Cc:

Description (Last modified by jtv)

libpqxx version 2.6.9 I am using platform sdk R2 for win2k3.

Successfully able to build libpq from postgresql sources for AMD64 by simply changing /machine:AMD64

I am compiling libpqxx for 64bit AMD processor. I simply changed win32/vc-libpqxx.mak /machine:I386 option to /machine:AMD64. but it fails to build. It seems that there are some changes in std::iterator in platform sdk. I got the following error

Microsoft (R) Program Maintenance Utility   Version 7.00.8882
Copyright (C) Microsoft Corp 1988-2000. All rights reserved.

        cl.exe /nologo /W3 /GX /FD /Wp64 /GR /c  /I "include" /I "C:\Work\64bit\
sc-contrib\libpqxx-2.6.9\..\postgresql-8.0.4\src/include" /I "C:\Work\64bit\sc-c
ontrib\libpqxx-2.6.9\..\postgresql-8.0.4\src/interfaces/libpq"  /D PGSTD="std" /
D "WIN32" /D "_MBCS" /D "_WINDOWS" /D "PQXX_INTERNAL" /MDd /Od /D "_LIB" /D "_DE
BUG" /Zc:forScope /Fo"ObjStaticDebug\\" /Fd"ObjStaticDebug\\" src/cursor.cxx
cl : Command line warning D9035 : option 'GX' has been deprecated and will be re
moved in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
cursor.cxx
include\pqxx\result.hxx(426) : error C2977: 'std::iterator' : too many template
arguments
        C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Inclu
de\crt\utility(70) : see declaration of 'std::iterator'
include\pqxx\result.hxx(435) : error C2955: 'std::iterator' : use of class templ
ate requires template argument list
        C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Inclu
de\crt\utility(70) : see declaration of 'std::iterator'

Can someone please help and let me know if i am missing something. I have to build libpqxx on 64 bit

Attachments

Change History

05/20/08 07:15:22 changed by jtv

  • description changed.

05/20/08 07:34:07 changed by jtv

Great news that you were able to build a libpq. On Windows, that's normally the hard part, and from what I hear 64-bit Windows isn't supported yet.

As for this problem: it seems the compiler is doing something that's not the STL as I know it. We'll need some more information.

First, do you know exactly which version of the standard library you are using? How does it declare std::iterator?

Next, Kirit tells me that this compiler setup is quite rare and it would help to know what Visual C++ version it corresponds to. He also tells me that there might conceivably be problems because of a new system that checks whether iterators are in range, even in release builds. If you know what I'm talking about, is that something your compiler/STL has?

05/21/08 07:23:49 changed by saurabh.ahuja@yahoo.co.in

Hi, I am using Microsoft ® Windows Server® 2003 R2 Platform SDK - March 2006 Edition It can be downloaded from the following location http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=en It defines iterator as follows

: public bidirectional_iterator_tag {};

// TEMPLATE CLASS iterator (from <iterator>)

template<class _C, class _Ty, class _D = ptrdiff_t>

struct iterator { typedef _C iterator_category; typedef _Ty value_type; typedef _D distance_type; };

You are right this version of STL has 3 arguments for std::iterator.There are some changes to standard STL which are described at the link below http://msdn.microsoft.com/en-us/library/zzz7ct0s(VS.80).aspx

After making some changes(mentioned in the above link) i am able to compile libpqxx on 64bit using the same compiler. Though i am in the process of linking libpqxx library with my binary.I will update you very soon once i will complete this exercise.

It would be great if someone will provide makefile for compilation on 64 bit and prerequisites.

However on a side note, i have to port my application on 64 bit Windows. So i am planning to use PostgreSQL as a 32 bit application and my application (64 bit) linked with libpqxx(64 bit) as 64 bit application. I am hoping my application(64 bit) would successfully be able to talk to postgresql(32 bit). Please correct me if i am wrong.

05/22/08 09:49:43 changed by jtv

It's a bit odd that the documentation you link to acknowledges a change in reverse_iterator but not what appears to be the exact same change in iterator, and that it gives a meaningful definition for iterator but not for reverse_iterator. But we can guess that they made the same changes in both.

Are you saying that the code compiles if you just remove the last two template arguments from the const_iterator_base typedef in result.hxx? If it also gets the tests to compile, run, and pass, it should be possible to add a workaround. The changes you've made could become the basis for a 64-bit Windows build setup in the package itself.

Have no worries about talking to a 32-bit database from a 64-bit application: the whole idea is to allow communication to a remote database server, which is routinely on a completely different platform. The protocol is designed to work across operating systems, word sizes, and byte orders. (Also, libpqxx has been teste on a variety 64-bit systems for well over 5 years—just not with Windows!).

05/23/08 07:08:48 changed by saurabh.ahuja@yahoo.co.in

Hi, Thanks for your help and support. o After passing 3 arguments to template and some other changes i was able to build libpqxx on 64 bit windows.But now i dropped the idea of using Platform SDK, reason being differences in STL.

o Now i am using Visual Studio 2005 for 64 bit compilation that has the correct version of STL. o I am using libpqxx-2.5.3 and not the latest version 2.6.9.

o I simply changed the /machine:I386 option to /machine:AMD64 and compiled.Although it gave lot of warnings which i am assuming is ok for the time being. It was successfully compiled however while creating DLL it gave me following error

binarystring.obj : error LNK2019: unresolved external symbol "class std::basic_s tring<char,struct std::char_traits<char>,class std::allocator<char> > cdecl pq xx::to_string<unsigned int64>(unsigned int64 const &)" (??$to_string@_K@pqxx @@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEB_K@Z) ref erenced in function "public: unsigned char const & cdecl pqxx::binarystring::a t(unsigned int64)const " (?at@binarystring@pqxx@@QEBAAEBE_K@Z) lib\libpqxx.dll : fatal error LNK1120: 1 unresolved externals NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\x 86_amd64\link.exe"' : return code '0x460' Stop. NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\n make.exe"' : return code '0x2' Stop.

o It seems that to_string template is not available for 64 bit signed/unsigned integers. Then i made the following change in src\util.cxx and this time DLL was created successfully.

Index: src/util.cxx =================================================================== --- src/util.cxx (revision 60506) +++ src/util.cxx (working copy) @@ -405,6 +405,11 @@

return to_string_unsigned(Obj);

}

+template<> string to_string(const size_t &Obj) +{ + return to_string_signed(Obj); +} +

template<> string to_string(const float &Obj) {

return to_string_float(Obj)

o Then i tried compiling test cases and after applying the above mentioned patch it gave me following error

Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.42 for x64 Copyright (C) Microsoft Corporation. All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

C:\Work\64bit\sc-contrib\libpqxx-2.5.3\win32>nmake /f test.mak all

Microsoft (R) Program Maintenance Utility Version 8.00.50727.42 Copyright (C) Microsoft Corporation. All rights reserved.

You can specify a specific testcase when running NMAKE. For example: NMAKE /f "test.mak" testcase Possible choices for testcase are TEST001 through TEST059 or ALL

test000.obj : error LNK2019: unresolved external symbol "class std::basic_string <char,struct std::char_traits<char>,class std::allocator<char> > cdecl pqxx::t o_string<unsigned int64>(unsigned int64 const &)" (??$to_string@_K@pqxx@@YA? AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEB_K@Z) referenc ed in function "void cdecl `anonymous namespace'::testitems<class pqxx::items< int,class std::vector<int,class std::allocator<int> > > >(class pqxx::items<int, class std::vector<int,class std::allocator<int> > > const &,unsigned int64)" ( ??$testitems@V?$items@HV?$vector@HV?$allocator@H@std@@@std@@@pqxx@@@?A0xbc7be66d @@YAXAEBV?$items@HV?$vector@HV?$allocator@H@std@@@std@@@pqxx@@_K@Z) ./lib\test000.exe : fatal error LNK1120: 1 unresolved externals NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\x 86_amd64\link.exe"' : return code '0x460' Stop.

o I am hoping you must have the got the problem after looking at the linking error.Now i want you to introduce template for to_string that accepts signed/unsigned 64 bit integers.

Also for your reference i am attaching the changes i have done for 64 bit compilation. Index: src/util.cxx =================================================================== --- src/util.cxx (revision 60506) +++ src/util.cxx (working copy) @@ -405,6 +405,11 @@

return to_string_unsigned(Obj);

}

+template<> string to_string(const size_t &Obj) +{ + return to_string_signed(Obj); +} +

template<> string to_string(const float &Obj) {

return to_string_float(Obj);

Index: win32/test.mak =================================================================== --- win32/test.mak (revision 60506) +++ win32/test.mak (working copy) @@ -37,9 +37,9 @@

/YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\"

LINK32=link.exe

-LINK32_FLAGS=$(LINK32_FLAG_LIB) kernel32.lib user32.lib \ +LINK32_FLAGS=$(LINK32_FLAG_LIB) kernel32.lib user32.lib bufferoverflowU.lib \

winspool.lib shell32.lib uuid.lib \

- /nologo /subsystem:console /machine:I386 \ + /nologo /subsystem:console /machine:AMD64 \

$(LINK32_FLAG_EXTRA) $(LIBPATH) /libpath:"lib"

TEST000: "$(OUTDIR)\test000.exe"

Index: win32/common =================================================================== --- win32/common (revision 60506) +++ win32/common (working copy) @@ -1,28 +1,3 @@ -!IF "$(OS)" == "Windows_NT" -NULL= -!ELSE -NULL=nul -!ENDIF - -#-STL options -STD=/D "PGSTD=std" -# If you are using a 3rd party STL like STLport, remember to check your path -# and be sure the STLport is included before the MSVC includes. VCVARS32.BAT -# doesn't know anything about the directories as defined in the IDE. I use -# set INCLUDE=\Utility\Code\STLport-4.5\stlport;%INCLUDE% -# STD=/D "PGSTD=_STL" - -# Depending on your STL library min/max need to be defined. Using STLport -# there is no need for libpqxx to redefine these for me. - -# The next line gives us the src directory to add additional include directories -# We need certain header files from the Postgres code. Specifically -# src/include/c.h -# src/include/config.h -# src/include/postgres_ext.h -# src/include/postgres_fe.h -# src/interfaces/libpq/libpq-fe.h -PGSQLSRC=/Project/postgresql-7.1.2/src -# If the LIBPQ library is not in the LIB environment or search path specified it here -LIBPATH=/libpath:"/Project/postgresql-7.1.2/src/interfaces/libpq/Release" - +STD=/D "PGSTD=std" +PGSQLSRC=C:\Work\64bit\sc-contrib\libpqxx-2.5.3\..\postgresql-8.0.4\src +LIBPATH=/libpath:"C:\Work\64bit\sc-contrib\libpqxx-2.5.3\..\postgresql-8.0.4\src\interfaces\libpq\Release" Index: win32/libpqxx.mak =================================================================== --- win32/libpqxx.mak (revision 60506) +++ win32/libpqxx.mak (working copy) @@ -62,9 +62,9 @@

/Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" \

LINK32=link.exe

-LINK32_FLAGS=kernel32.lib wsock32.lib user32.lib gdi32.lib winspool.lib \ +LINK32_FLAGS=kernel32.lib wsock32.lib user32.lib bufferoverflowU.lib gdi32.lib winspool.lib \

comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib \

- odbc32.lib odbccp32.lib /nologo /dll /machine:I386 \ + odbc32.lib odbccp32.lib /nologo /dll /machine:AMD64 \

/out:"$(OUTFILE).dll" /implib:"$(OUTFILE).lib" \ $(LINK32_FLAG_EXTRA) $(LIBPATH)

05/23/08 12:41:10 changed by jtv

Lots of points here! Glad to see you're making progress.

(By the way, since we're going into a lot of detail here: you can use wiki syntax in these bug tickets. Try reading the documentation linked from the TracWiki page, it will make it a lot easier to get your text formatted the way you want!)

Now, for the individual points:

  • libpqxx 2.5.3 is really, really old. Have you tried the latest 3.0 development snapshots? They're rebuilt daily from the development source tree. Windows support should be much better there.
  • Warnings. Yes, you'll see a lot of them with Visual C++; I do try to keep the library warning-free but many of these seem to be unavoidable. If you have any particularly annoying ones, we have a facility for disabling them in libpqxx code without affecting the compiler's warning levels for your own code.
  • The link errors look as if either you're not linking to the standard library, or you're linking to a different version of the standard library than you compiled against (or maybe the same library but with very different settings). An old object file sticking around from before your compiler change maybe?
  • to_string does work for 64-bit integers, but if regular "long" is not a 64-bit type on your system, you'll need the PQXX_HAVE_LONG_LONG and PQXX_ALLOW_LONG_LONG macros defined in include/pqxx/config-public-compiler.h. (We can't add a size_t specialization to to_string because size_t is a typedef to one of the builtin integral types, and then that type might end up with two to_string specializations).

06/15/08 03:02:29 changed by jtv

  • owner deleted.

08/26/08 07:00:10 changed by saurabh.ahuja@yahoo.co.in

Hi,

I had to use Libpqxx-2.5.3. I am able to build it for 64 bit Windows with some warnings.I have tested my application(64 bit) which talks to 32 bit postgresql.Although i didnt get time to build libpqxx test and to run it. Following are the changes i had to do to build libpqxx on 64 bit.

Index: src/binarystring.cxx 
=================================================================== 
--- src/binarystring.cxx	(revision 62281)
+++ src/binarystring.cxx	(working copy)
@@ -91,7 +91,7 @@
     if (!m_size)
       throw out_of_range("Accessing empty binarystring");
     throw out_of_range("binarystring index out of range: " +
-	to_string(n) + " (should be below " + to_string(m_size) + ")"); 
+	to_string((int)n) + " (should be below " + to_string((int)m_size) + ")"); 
   } 
   return data()[n]; 
 }
Index: win32/libpqxx.mak 
===================================================================
--- win32/libpqxx.mak	(revision 62281)
+++ win32/libpqxx.mak	(working copy)
@@ -62,9 +62,9 @@
 	/Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" \
 
 LINK32=link.exe
-LINK32_FLAGS=kernel32.lib wsock32.lib user32.lib gdi32.lib winspool.lib \
+LINK32_FLAGS=kernel32.lib wsock32.lib user32.lib bufferoverflowU.lib gdi32.lib winspool.lib \
 	comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib \
-	odbc32.lib odbccp32.lib /nologo /dll /machine:I386 \
+	odbc32.lib odbccp32.lib /nologo /dll /machine:AMD64 \
 	/out:"$(OUTFILE).dll" /implib:"$(OUTFILE).lib" \
 	$(LINK32_FLAG_EXTRA) $(LIBPATH) 

Thanks a ton for the help.

Saurabh Ahuja

11/02/08 01:49:36 changed by jtv

  • milestone deleted.

Add/Change #144 (Compile libpqxx Windows platform SDK AMD64)




Change Properties
Action