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 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
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 | Content-Type | Size |
---|---|---|
c++configure.patch | text/plain | 13.5 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Kurt Harriman | 2008-12-05 09:20:18 | Re: Mostly Harmless: c++exception - patch 4 of 4 |
Previous Message | Kurt Harriman | 2008-12-05 09:16:37 | Re: Mostly Harmless: c++bookends - patch 2 of 4 |