8000 Configure option --with-cxx-main=/usr/bin/clang++ not working · Issue #93744 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Configure option --with-cxx-main=/usr/bin/clang++ not working #93744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MaxwellDupre opened this issue Jun 12, 2022 · 20 comments
Closed

Configure option --with-cxx-main=/usr/bin/clang++ not working #93744

MaxwellDupre opened this issue Jun 12, 2022 · 20 comments
Labels
build The build process and cross-build type-bug An unexpected behavior, bug, or error

Comments

@MaxwellDupre
Copy link
Contributor

Configure option --with-cxx-main=/usr/bin/clang++ not working

My environment

  • CPython versions tested on:
    Latest 3.12.0.a0 tried on other but CC=/usr/bin/clang not working on those, so pointless to try
  • Operating system and architecture:
    fedora 5.17.13-300.fc36.x86_64

Configure options
--with-cxx-main=/usr/bin/clang++ CC=/usr/bin/clang
runs and gives at end:
configure: creating Modules/Setup.local
configure: creating Makefile
configure:

Then:
make
/usr/bin/clang++ -c -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Programs/python.o ./Programs/python.c
clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
error: invalid argument '-std=c11' not allowed with 'C++'
make: *** [Makefile:1373: Programs/python.o] Error 1

See Discuss report

Tried configure with --with-cxx-main=/usr/bin/g++ CC=/usr/bin/gcc
then
make
cc1plus: warning: ‘-Werror=’ argument ‘-Werror=implicit-function-declaration’ is not valid for C++
cc1plus: warning: command-line option ‘-std=c11’ is valid for C/ObjC but not for C++

Shows source files being compiled and linked and actually builds python executable, so this works.

@MaxwellDupre MaxwellDupre added the type-bug An unexpected behavior, bug, or error label Jun 12, 2022
@kumaraditya303
Copy link
Contributor

If you do CC=clang ./configure it works fine. This is not a Python bug, you can ask this on discourse Users category.

@kumaraditya303 kumaraditya303 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2022
@MaxwellDupre
Copy link
Contributor Author
MaxwellDupre commented 8000 Jun 21, 2022

This is a bug: explain why its not!

I have raised a question on discourse and it was not answered!

I am not complaining about CC=clang ./configure - this works for me BUT the option
--with-cxx-main=/usr/bin/clang++ CC=/usr/bin/clang
does not!!!

@tiran
Copy link
Member
tiran commented Jun 21, 2022

I can reproduce the problem and confirm that it's a bug in our configure script.

$ CC=clang ../../configure --with-cxx-main=clang++ -C
$ make -j1
clang++ -c -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I../../Include/internal -IObjects -IInclude -IPython -I. -I../../Include    -DPy_BUILD_CORE -o Programs/python.o ../../Programs/python.c
clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
error: invalid argument '-std=c11' not allowed with 'C++'
make: *** [Makefile:1376: Programs/python.o] Error 1

@tiran tiran reopened this Jun 21, 2022
@erlend-aasland
Copy link
Contributor

This is a bug: explain why its not!

Please remain calm and use a polite tone.

I have raised a question on discourse and it was not answered!

25 minutes ago. There is no guarenteed response time; we are all volunteers, trying to improve CPython in our free time. Once again, please use a polite tone.

@erlend-aasland erlend-aasland added the build The build process and cross-build label Jun 21, 2022
@kumaraditya303
Copy link
Contributor
kumaraditya303 commented Jun 21, 2022

The discuss report 1 you linked has been answered by a core dev and the author claimed that by syncing with 3.12 it works and then you are saying that it has not been answered. Please remain calm so that our autoconf experts will take a look. Thanks

Footnotes

  1. https://discuss.python.org/t/compiling-python-with-clang/16323/4

@tiran
Copy link
Member
tiran commented Jun 21, 2022

GCC's C++ compiler just warns about -stdc=c11 option. Do we support building with Clang's C++ compiler?

g++ -c -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden  -I../../Include/internal -IObjects -IInclude -IPython -I. -I../../Include    -DPy_BUILD_CORE -o Programs/python.o ../../Programs/python.c
cc1plus: warning: ‘-Werror=’ argument ‘-Werror=implicit-function-declaration’ is not valid for C++
cc1plus: warning: command-line option ‘-std=c11’ is valid for C/ObjC but not for C++

@erlend-aasland
Copy link
Contributor
erlend-aasland commented Jun 21, 2022

Do we support building with Clang's C++ compiler?

AFAICS, no C++ is mentioned in PEP 11. However, @vstinner has recently pushed some changes to make the code base friendlier to C++ compilers.

@encukou
Copy link
Member
encukou commented Jun 21, 2022

AFAIK Victor's work is on public headers, not Python itself. While you can use the C-API with C++, Python itself is written in C.

Supporting ./configure with C++ seems rather pointless to me, is there a use case where you can't use the C compiler?

@erlend-aasland
Copy link
Contributor

AFAIK Victor's work is on public headers, not Python itself [...]

Yes, correct. That's a related issue, but not directly relevant for this issue.

@erlend-aasland
Copy link
Contributor
erlend-aasland commented Jun 21, 2022

See also the docs for the --with-cxx-main option: https://docs.python.org/3/using/configure.html

@tiran
Copy link
Member
tiran commented Jun 21, 2022

--with-cxx-main is a feature that was introduced in 9501219 (1999). Is still useful?

8000

@erlend-aasland
Copy link
Contributor
erlend-aasland commented Jun 21, 2022

Here's my 2 cents:

PEP 11 does not say anything about C++ compilers. The current option is broken with at least one C++ compiler two C++ compilers.
I say we drop it.

@encukou
Copy link
Member
encukou commented Jun 21, 2022

I guess the use case might have been ensuring that we can use a C++ compiler/linker with libpython? testcppext does that now.

Anyway, if we do drop it, 3.12a0 is the perfect time.

@vstinner
Copy link
Member

See also the docs for the --with-cxx-main option: https://docs.python.org/3/using/configure.html

I never used it. I don't see the point of building the whole Python in C... but only the main() function with C++.

Nowadays, most Linux distributions distribute a shared libpython library, so it's trivial to build your own main() function implemented in C++ which calls Py_BytesMain().

Each time I tried --with-cxx-main, I only got errors and I failed to understand its purpose.

I suggest to remove this configure option.

@vstinner
Copy link
Member

PEP 11 does not say anything about C++ compilers.

It would be nice to update PEP 11 to require the Python C API to be usable in C++, at least with C++11.

Since Python 3.11, compatibility with C++11 is now tested. I recently added a test on C++03.

@vstinner
Copy link
Member

On Fedora 36, I failed to build Python 3.10 with ./configure --with-cxx-main=g++ CC=gcc. g++ fails to build Programs/_testembed.c.

So I don't think that this issue is about fixing Python. It's like a "new feature". IMO configure --with-cxx-main=... option was broken for many years.

Examples of g++ errors:

Include/internal/pycore_atomic.h is incompatible C++:

./Include/internal/pycore_atomic.h:38:32: error: 'memory_order_relaxed' was not declared in this scope
   38 |     _Py_memory_order_relaxed = memory_order_relaxed,

putenv() error:

./Programs/_testembed.c:168:12: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  168 |     putenv("PYTHONMALLOC=");

Many errors related to Py_BUILD_ASSERT_EXPR() used by Py_ARRAY_LENGTH():

In file included from ./Include/Python.h:51,
                 from ./Programs/_testembed.c:8:
./Include/pymacro.h:61:30: error: '__builtin_types_compatible_p' was not declared in this scope
   61 |      + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/pymacro.h:40:27: note: in definition of macro 'Py_BUILD_ASSERT_EXPR'
   40 |     (sizeof(char [1 - 2*!(cond)]) - 1)
      |                           ^~~~
./Programs/_testembed.c:319:13: note: in expansion of macro 'Py_ARRAY_LENGTH'
  319 |     Py_Main(Py_ARRAY_LENGTH(argv), argv);
      |             ^~~~~~~~~~~~~~~
./Include/pymacro.h:40:13: error: expected primary-expression before 'char'
   40 |     (sizeof(char [1 - 2*!(cond)]) - 1)
      |             ^~~~
./Include/pymacro.h:61:8: note: in expansion of macro 'Py_BUILD_ASSERT_EXPR'
   61 |      + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \
      |        ^~~~~~~~~~~~~~~~~~~~
./Programs/_testembed.c:319:13: note: in expansion of macro 'Py_ARRAY_LENGTH'
  319 |     Py_Main(Py_ARRAY_LENGTH(argv), argv);
      |             ^~~~~~~~~~~~~~~
./Include/pymacro.h:40:13: error: expected ')' before 'char'
   40 |     (sizeof(char [1 - 2*!(cond)]) - 1)
      |            ~^~~~
./Include/pymacro.h:61:8: note: in expansion of macro 'Py_BUILD_ASSERT_EXPR'
   61 |      + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \
      |        ^~~~~~~~~~~~~~~~~~~~
./Programs/_testembed.c:319:13: note: in expansion of macro 'Py_ARRAY_LENGTH'
  319 |     Py_Main(Py_ARRAY_LENGTH(argv), argv);
      |             ^~~~~~~~~~~~~~~
./Programs/_testembed.c:319:41: error: expected ')' before ';' token
  319 |     Py_Main(Py_ARRAY_LENGTH(argv), argv);
      |                                         ^
      |                                         )
./Include/pymacro.h:40:5: note: to match this '('
   40 |     (sizeof(char [1 - 2*!(cond)]) - 1)
      |     ^
./Include/pymacro.h:61:8: note: in expansion of macro 'Py_BUILD_ASSERT_EXPR'
   61 |      + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \
      |        ^~~~~~~~~~~~~~~~~~~~
./Programs/_testembed.c:319:13: note: in expansion of macro 'Py_ARRAY_LENGTH'
  319 |     Py_Main(Py_ARRAY_LENGTH(argv), argv);
      |             ^~~~~~~~~~~~~~~
./Programs/_testembed.c:319:41: error: expected ')' before ';' token
  319 |     Py_Main(Py_ARRAY_LENGTH(argv), argv);
      |                                         ^
      |                                         )
./Include/pymacro.h:60:5: note: to match this '('
   60 |     (sizeof(array) / sizeof((array)[0]) \
      |     ^
./Programs/_testembed.c:319:13: note: in expansion of macro 'Py_ARRAY_LENGTH'
  319 |     Py_Main(Py_ARRAY_LENGTH(argv), argv);
      |             ^~~~~~~~~~~~~~~

@erlend-aasland
Copy link
Contributor

I guess we could remove it under this ticket. Let's go 🚀

@vstinner
Copy link
Member

I wrote a large PR removing more than just --with-cxx-main: PR #94063.

vstinner added a commit that referenced this issue Aug 5, 2022
Remove the "configure --with-cxx-main" build option: it didn't work
for many years. Remove the MAINCC variable from configure and
Makefile.

The MAINCC variable was added by the issue gh-42471: commit
0f48d98. Previously, --with-cxx-main
was named --with-cxx.

Keep CXX and LDCXXSHARED variables, even if they are no longer used
by Python build system.
@vstinner
Copy link
Member
vstinner commented Aug 5, 2022

Fixed by 398ed84 which removes the configure option.

It's easy to embed Python in a C++ application: https://docs.python.org/dev/extending/embedding.html

@erlend-aasland
Copy link
Contributor

Thanks for the fix, Victor 😃 Closing this as fixed 🚀

iritkatriel pushed a commit to iritkatriel/cpython that referenced this issue Aug 11, 2022
Remove the "configure --with-cxx-main" build option: it didn't work
for many years. Remove the MAINCC variable from configure and
Makefile.

The MAINCC variable was added by the issue pythongh-42471: commit
0f48d98. Previously, --with-cxx-main
was named --with-cxx.

Keep CXX and LDCXXSHARED variables, even if they are no longer used
by Python build system.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

6 participants
0