Skip to content

Commit 0f48d98

Browse files
committed
Patch #1324762: Change --with-cxx to --with-cxx-main.
1 parent 15be5ec commit 0f48d98

File tree

6 files changed

+281
-356
lines changed

6 files changed

+281
-356
lines changed

Makefile.pre.in

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ VPATH= @srcdir@
3030

3131
CC= @CC@
3232
CXX= @CXX@
33+
MAINCC= @MAINCC@
3334
LINKCC= @LINKCC@
3435
AR= @AR@
3536
RANLIB= @RANLIB@
@@ -157,7 +158,6 @@ LIBC= @LIBC@
157158
SYSLIBS= $(LIBM) $(LIBC)
158159
SHLIBS= @SHLIBS@
159160

160-
MAINOBJ= @MAINOBJ@
161161
THREADOBJ= @THREADOBJ@
162162
DLINCLDIR= @DLINCLDIR@
163163
DYNLOADFILE= @DYNLOADFILE@
@@ -326,9 +326,9 @@ LIBRARY_OBJS= \
326326
all: $(BUILDPYTHON) oldsharedmods sharedmods
327327

328328
# Build the interpreter
329-
$(BUILDPYTHON): Modules/$(MAINOBJ) $(LIBRARY) $(LDLIBRARY)
329+
$(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY)
330330
$(LINKCC) $(LDFLAGS) $(LINKFORSHARED) -o $@ \
331-
Modules/$(MAINOBJ) \
331+
Modules/python.o \
332332
$(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
333333

334334
platform: $(BUILDPYTHON)
@@ -448,8 +448,8 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
448448
-DVPATH='"$(VPATH)"' \
449449
-o $@ $(srcdir)/Modules/getpath.c
450450

451-
Modules/ccpython.o: $(srcdir)/Modules/ccpython.cc
452-
$(CXX) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/ccpython.cc
451+
Modules/python.o: $(srcdir)/Modules/python.c
452+
$(MAINCC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/python.c
453453

454454

455455
$(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
@@ -537,7 +537,7 @@ PYTHON_HEADERS= \
537537
Include/weakrefobject.h \
538538
pyconfig.h
539539

540-
$(LIBRARY_OBJS) $(MODOBJS) Modules/$(MAINOBJ): $(PYTHON_HEADERS)
540+
$(LIBRARY_OBJS) $(MODOBJS) Modules/python.o: $(PYTHON_HEADERS)
541541

542542

543543
######################################################################
@@ -813,7 +813,7 @@ libainstall: all
813813
fi; \
814814
fi
815815
$(INSTALL_DATA) Modules/config.c $(DESTDIR)$(LIBPL)/config.c
816-
$(INSTALL_DATA) Modules/$(MAINOBJ) $(DESTDIR)$(LIBPL)/$(MAINOBJ)
816+
$(INSTALL_DATA) Modules/python.o $(DESTDIR)$(LIBPL)/python.o
817817
$(INSTALL_DATA) $(srcdir)/Modules/config.c.in $(DESTDIR)$(LIBPL)/config.c.in
818818
$(INSTALL_DATA) Makefile $(DESTDIR)$(LIBPL)/Makefile
819819
$(INSTALL_DATA) Modules/Setup $(DESTDIR)$(LIBPL)/Setup

Misc/NEWS

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ Library
8282
Build
8383
-----
8484

85+
- Patch #1324762:Remove ccpython.cc; replace --with-cxx with
86+
--with-cxx-main. Link with C++ compiler only if --with-cxx-main was
87+
specified. (Can be overriden by explicitly setting LINKCC.) Decouple
88+
CXX from --with-cxx-main, see description in README.
89+
8590
- Patch #1429775: Link extension modules with the shared libpython.
8691

8792
C API

Modules/ccpython.cc

-11
This file was deleted.

README

+29-7
Original file line numberDiff line numberDiff line change
@@ -1045,13 +1045,35 @@ Modules/getpath.o.
10451045
--with-libs='libs': Add 'libs' to the LIBS that the python interpreter
10461046
is linked against.
10471047

1048-
--with-cxx=<compiler>: Some C++ compilers require that main() is
1049-
compiled with the C++ if there is any C++ code in the application.
1050-
Specifically, g++ on a.out systems may require that to support
1051-
construction of global objects. With this option, the main() function
1052-
of Python will be compiled with <compiler>; use that only if you
1053-
plan to use C++ extension modules, and if your compiler requires
1054-
compilation of main() as a C++ program.
1048+
--with-cxx-main=<compiler>: If you plan to use C++ extension modules,
1049+
then -- on some platforms -- you need to compile python's main()
1050+
function with the C++ compiler. With this option, make will use
1051+
<compiler> to compile main() *and* to link the python executable.
1052+
It is likely that the resulting executable depends on the C++
1053+
runtime library of <compiler>. (The default is --without-cxx-main.)
1054+
1055+
There are platforms that do not require you to build Python
1056+
with a C++ compiler in order to use C++ extension modules.
1057+
E.g., x86 Linux with ELF shared binaries and GCC 3.x, 4.x is such
1058+
a platform. We recommend that you configure Python
1059+
--without-cxx-main on those platforms because a mismatch
1060+
between the C++ compiler version used to build Python and to
1061+
build a C++ extension module is likely to cause a crash at
1062+
runtime.
1063+
1064+
The Python installation also stores the variable CXX that
1065+
determines, e.g., the C++ compiler distutils calls by default
1066+
to build C++ extensions. If you set CXX on the configure command
1067+
line to any string of non-zero length, then configure won't
1068+
change CXX. If you do not preset CXX but pass
1069+
--with-cxx-main=<compiler>, then configure sets CXX=<compiler>.
1070+
In all other cases, configure looks for a C++ compiler by
1071+
some common names (c++, g++, gcc, CC, cxx, cc++, cl) and sets
1072+
CXX to the first compiler it finds. If it does not find any
1073+
C++ compiler, then it sets CXX="".
1074+
1075+
Similarly, if you want to change the command used to link the
1076+
python executable, then set LINKCC on the configure command line.
10551077

10561078

10571079
--with-pydebug: Enable additional debugging code to help track down

0 commit comments

Comments
 (0)