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

Re: Mostly Harmless: c++configure - patch 3 of 4

From: Kurt Harriman <harriman(at)acm(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Mostly Harmless: c++configure - patch 3 of 4
Date: 2008-12-05 09:18:46
Message-ID: 4938F1F6.8040005@acm.org (view raw or flat)
Thread:
Lists: pgsql-hackers
(Re-sending just the third of four patches: c++configure)

These patches are based on CVS head in which the latest commit was
  user:        petere
  date:        Thu Dec 04 17:51:28 2008 +0000
  summary:     Default values for function arguments

3. c++configure

     This patch adds C++ support to the PostgreSQL build system.

     After you have applied the patch, cd to the top of the source
     tree (to the directory containing the file 'configure.in') and
     execute these two commands to regenerate the 'configure' script
     and some related files:
         autoconf
         autoheader

     Much as it already does for the C compiler, the 'configure' script
     will try to find the C++ compiler and set up appropriate command
     line options.  If 'configure' finds a C++ compiler, it will set up
     src/Makefile.global to define the following makefile variables:

         CXX = command for invoking C++ compiler
         CXXCPP = command for invoking C++ preprocessor
         CXXFLAGS = C++ compiler options
         GXX = 'yes' if the C++ compiler is gcc/g++

     Implicit rules are defined so that gmake will automatically invoke
     the C++ compiler using the above variables given a source file name
     suffixed with '.cpp' or '.cc'.  So, to add a file named marvin.cpp
     to the build, just add 'marvin.o' to the OBJS list in the Makefile.

     To C++-compile a file with '.c' suffix, the Makefile should list
     the .o file in both OBJS and CXXOBJS.

     The pg_config utility can be used to display the CXX and CXXFLAGS.

     Most C++ code typically uses some C++ features whose implementation
     makes use of the compiler's runtime library: exceptions, static
     constructors, new/delete, STL containers, stream I/O, etc.  Specify
     the following 'configure' option to link the C++ runtime library
     into the postgres backend:

         --enable-cplusplus

     If --enable-cplusplus is specified, the makefile variable
     'enable_cplusplus' will be set to 'yes', and pg_config.h will
     #define ENABLE_CPLUSPLUS.

     To ensure that the C++ runtime library is properly initialized,
     on some platforms it is necessary for the main() function to be
     compiled as C++.  Therefore, if --enable-cplusplus is configured,
     src/backend/main/main.c will be compiled as C++.  This is
     handled by the following lines in src/backend/main/Makefile:

         ifeq ($(enable_cplusplus),yes)
         CXXOBJS = main.o
         endif

     Fortunately, main.c can be compiled as either C or C++ with no
     difficulty after applying the c++reserved and c++bookends
     patches.  To make main.c bilingual, all that was needed was
     a pair of bookends around its #includes.

     Limitations:

     - I haven't added support for profiling and code coverage for
       C++.  Automatic dependency generation is supported, however.

     - This ought to work on platforms which use GCC, and maybe some
       others.  The only one I have tested is x86_32 Linux with GCC
       4.1.2.  Hopefully some interested hackers will try it on
       platforms to which they have access, and post the results.


Attachment: c++configure.patch
Description: text/plain (13.5 KB)

In response to

Responses

pgsql-hackers by date

Next:From: Kurt HarrimanDate: 2008-12-05 09:20:18
Subject: Re: Mostly Harmless: c++exception - patch 4 of 4
Previous:From: Kurt HarrimanDate: 2008-12-05 09:16:37
Subject: Re: Mostly Harmless: c++bookends - patch 2 of 4

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