This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Failed to build with --with-cxx-main=g++-9.2.0
Type: enhancement Stage: patch review
Components: Build Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Marco Sulla, cludwig, jkloth, vstinner, xtreak
Priority: normal Keywords: patch

Created on 2020-02-20 11:37 by Marco Sulla, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 18721 open Marco Sulla, 2020-03-01 14:42
Messages (14)
msg362313 - (view) Author: Marco Sulla (Marco Sulla) * Date: 2020-02-20 11:37
I tried to compile Python 3.9 with:


CC=gcc-9.2.0  ./configure --enable-optimizations --with-lto --with-cxx-main=g++-9.2.0
make -j 2

I got this error:

g++-9.2.0 -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -fprofile-generate -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Programs/_testembed.o ./Programs/_testembed.c
cc1plus: warning: ‘-Werror=’ argument ‘-Werror=implicit-function-declaration’ is not valid for C++
cc1plus: warning: command line option ‘-std=c99’ is valid for C/ObjC but not for C++
sed -e "s,@EXENAME@,/usr/local/bin/python3.9," < ./Misc/python-config.in >python-config.py
LC_ALL=C sed -e 's,\$(\([A-Za-z0-9_]*\)),\$\{\1\},g' < Misc/python-config.sh >python-config
gcc-9.2.0 -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -fprofile-generate -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE \
      -DGITVERSION="\"`LC_ALL=C git --git-dir ./.git rev-parse --short HEAD`\"" \
      -DGITTAG="\"`LC_ALL=C git --git-dir ./.git describe --all --always --dirty`\"" \
      -DGITBRANCH="\"`LC_ALL=C git --git-dir ./.git name-rev --name-only HEAD`\"" \
      -o Modules/getbuildinfo.o ./Modules/getbuildinfo.c
In file included from ./Include/internal/pycore_atomic.h:15,
                 from ./Include/internal/pycore_gil.h:11,
                 from ./Include/internal/pycore_pystate.h:11,
                 from ./Programs/_testembed.c:10:
/usr/local/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/stdatomic.h:40:9: error: ‘_Atomic’ does not name a type

I suppose simply `Programs/_testembed.c` is a C source file and must not be compiled with g++

PS: as a workaround, `--with-cxx-main=gcc-9.2.0` works, but probably it's not optimal.
msg362315 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-02-20 12:08
See also https://bugs.python.org/issue23644
msg362545 - (view) Author: Marco Sulla (Marco Sulla) * Date: 2020-02-23 22:27
I think in this case the error is more trivial: simply `Programs/_testembed.c` is compiled with g++ but it should be compiled with gcc.

Indeed, there are much gcc-only options in the compilation of `Programs/_testembed.c`, and g++ complains about them:

> cc1plus: warning: ‘-Werror=’ argument ‘-Werror=implicit-function-declaration’ is not valid for C++
> cc1plus: warning: command line option ‘-std=c99’ is valid for C/ObjC but not for C++
msg363026 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-02-29 22:44
_testembed is build by Makefile:

Programs/_testembed: Programs/_testembed.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
	$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS)

with:

MAINCC=		$(CC)
LINKCC=		$(PURIFY) $(MAINCC)

I'm not sure how g++ landed in LINKCC or MAINCC.
msg363027 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-02-29 22:45
> See also https://bugs.python.org/issue23644

This issue is unrelated and has been fixed.
msg363064 - (view) Author: Marco Sulla (Marco Sulla) * Date: 2020-03-01 14:34
The problem is here:

Programs/_testembed.o: $(srcdir)/Programs/_testembed.c
	$(MAINCC) -c $(PY_CORE_CFLAGS) -o $@ $(srcdir)/Programs/_testembed.c

`MAINCC` in my Makefile is `g++-9`. Probably, MAINCC is set to the value of ``--with-cxx-main`, if specified.

I replaced `MAINCC` with `CC` at this line, and it works.
msg363065 - (view) Author: Marco Sulla (Marco Sulla) * Date: 2020-03-01 14:44
https://github.com/python/cpython/pull/18721
msg363068 - (view) Author: Marco Sulla (Marco Sulla) * Date: 2020-03-01 15:22
Mmmmhhhh... wait a moment. It seems the behavior is intended:

https://bugs.python.org/issue1324762

I quote:


The patch contains the following changes:
[...]
2) The compiler used to translate python's main() function is 
stored in the configure / Makefile variable MAINCC. By 
default, MAINCC=$(CC). [...] If 
--with-cxx-main=<compiler> is on the configure command 
line, then MAINCC=<compiler>.


Honestly I have _no idea_ why this change was made. Unluckily, the link to the discussion is broken.
msg363069 - (view) Author: Jeremy Kloth (jkloth) * Date: 2020-03-01 16:32
What seems to be, at least, the conclusion of the thread:

https://mail.python.org/archives/list/python-dev@python.org/thread/YXMD5EIHAODRZGTQ3HU74OPGEBAVCSK6/
msg363104 - (view) Author: Marco Sulla (Marco Sulla) * Date: 2020-03-01 22:43
Okay... if I have understood well, the problem is with C++ Extensions.

Some questions:

1. does this problem exists yet?
2. if yes, maybe Python have to wrap the python.c and _testembed.c so they can also be compiled with a C++ compiler?
3. --with-cxx-main is not somewhat misleading? There's no documentation, and I interpreted it as "the _main_ compiler for C++", while it means "the compiler for main()". Should I suggest (maybe in another issue) to deprecate it and use --with-mainfun-compiler ?
msg363105 - (view) Author: Marco Sulla (Marco Sulla) * Date: 2020-03-01 22:51
Furthermore, I have not understood a think: if I understood well, --with-cxx-main is used on _some_ platforms that have problems with C++ extensions. What platforms? Is there somewhere a unit test for testing if Python compiled on one of these platforms with -with-cxx-main=<some_c++_compiler> works, and if a C++ extension works with this build?
msg363227 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-03-03 00:39
This seems like a duplicate of https://bugs.python.org/issue35912
msg363245 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-03 09:08
I marked bpo-35912 as a duplicate of this issue (which has a longer history).
msg363296 - (view) Author: Marco Sulla (Marco Sulla) * Date: 2020-03-03 19:53
I agree with Pablo Galindo Salgado: https://bugs.python.org/issue35912#msg334942

The "quick and dirty" solution is to change MAINCC to CC, for _testembed.c AND python.c (g++ fails with both).

After that, _testembed.c and python.c should be changed so they can be compiled with a c++ compiler, and a system test should be added.

Anyway, I found the original patch:
https://bugs.python.org/file6816/cxx-main.patch

In the original patch, the README contained detailed information. I think these informations could be restored, maybe in ./configure --help

Anyway, I have a question. In README, it's stated:

There are platforms that do not require you to build Python
with a C++ compiler in order to use C++ extension modules.
E.g., x86 Linux with ELF shared binaries and GCC 3.x, 4.x is such
a platform.

All x86 platforms? Also x86-64? And what does it means "Linux with ELF"? It means that Linux has shared libraries or that Python is compiled with --enable-shared? And what it means gcc 3 and 4? It means gcc 3+?
History
Date User Action Args
2022-04-11 14:59:26adminsetgithub: 83878
2020-08-08 19:52:53pablogsalsetnosy: - pablogsal
2020-03-03 19:53:11Marco Sullasetmessages: + msg363296
2020-03-03 09:08:45vstinnersetmessages: + msg363245
2020-03-03 09:08:31vstinnerlinkissue35912 superseder
2020-03-03 00:39:30pablogsalsetnosy: + pablogsal
messages: + msg363227
2020-03-01 22:51:11Marco Sullasetmessages: + msg363105
2020-03-01 22:43:50Marco Sullasetmessages: + msg363104
2020-03-01 16:32:19jklothsetnosy: + jkloth
messages: + msg363069
2020-03-01 15:22:16Marco Sullasetnosy: + cludwig
messages: + msg363068
2020-03-01 14:44:37Marco Sullasetmessages: + msg363065
2020-03-01 14:42:42Marco Sullasetkeywords: + patch
stage: patch review
pull_requests: + pull_request18079
2020-03-01 14:34:47Marco Sullasetmessages: + msg363064
2020-02-29 22:45:41vstinnersetmessages: + msg363027
2020-02-29 22:44:57vstinnersetmessages: + msg363026
2020-02-23 22:27:16Marco Sullasetmessages: + msg362545
2020-02-20 12:08:36xtreaksetnosy: + xtreak, vstinner
messages: + msg362315
2020-02-20 11:37:58Marco Sullacreate