(Re-sending just the third of four patches: c++configure)
These patches are based on CVS head in which the latest commit was
date: Thu Dec 04 17:51:28 2008 +0000
summary: Default values for function arguments
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:
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:
If --enable-cplusplus is specified, the makefile variable
'enable_cplusplus' will be set to 'yes', and pg_config.h will
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:
CXXOBJS = main.o
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.
- 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.
In response to
pgsql-hackers by date
|Next:||From: Kurt Harriman||Date: 2008-12-05 09:20:18|
|Subject: Re: Mostly Harmless: c++exception - patch 4 of 4|
|Previous:||From: Kurt Harriman||Date: 2008-12-05 09:16:37|
|Subject: Re: Mostly Harmless: c++bookends - patch 2 of 4|