Compiling Python with clang? - Python Help - Discussions on Python.org
Compiling Python with clang? Python Help mikecm (mike McLeod) June 7, 2022, 2:46pm 1 I am wondering if its possible to compile with clang? Tried to add clang to 3.10.5, 3.11.0b3 & 3.12.0a0 with ./configure --enable-optimizations --with-lto --with-cxx-main=/usr/bin/clang++ CC=/usr/bin/clang … creating Makefile Running code to generate profile data (this can take a while): find: ‘build’: No such file or directory… Building with support for profile generation: clang-14: warning: treating ‘c’ input as ‘c++’ when in C++ mode, this behavior is deprecated [-Wdeprecated] error: invalid argument ‘-std=c99’ not allowed with ‘C++’ make[3]: *** [Makefile:813: Programs/python.o] Error 1 make[3]: *** Waiting for unfinished jobs… make[2]: *** [Makefile:531: build_all_generate_profile] Error 2 make[1]: *** [Makefile:507: profile-gen-stamp] Error 2 make: *** [Makefile:519: profile-run-stamp] Error 2 Makefile Lines 85-88: CFLAGS_NODIST is used for building the interpreter and stdlib C extensions.
Use it when a compiler flag should not be part of the distutils CFLAGS once Python is installed (Issue #21121 ). CONFIGURE_CFLAGS_NODIST= -flto -g -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden latest 3.12 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++’ I have seen clang build on version 2 but not 3.
The config.log looks reasonable. Is this a bug (I think I understand the error but cant see where the -std=c99 / c11 is created) or am I missing something? smontanaro (Skip Montanaro) June 8, 2022, 12:52am 2 Configuring like so ./configure CC=/usr/bin/clang works for me. mikecm (mike McLeod) June 8, 2022, 11:38am 3 Not working for me: 3104 make: Entering directory ‘/home/me/Documents/Python/Python-3.10.4’ error: unable to open output file ‘Python/sysmodule.o’: ‘Operation not permitted’ 1 error generated. make: *** [Makefile:839: Python/sysmodule.o] Error 1 make: Leaving directory ‘/home/me/Documents/Python/Python-3.10.4’ Latest 3.12 Modules/getbuildinfo.o: file not recognized: file format not recognized clang-14: error: linker command failed with exit code 1 (use -v to see invocation) make[3]: *** [Makefile:1104: _bootstrap_python] Error 1 make[3]: Leaving directory ‘/home/me/Documents/GitHub/cpython’ make[2]: *** [Makefile:764: build_all_generate_profile] Error 2 make[2]: Leaving directory ‘/home/me/Documents/GitHub/cpython’ make[1]: *** [Makefile:740: profile-gen-stamp] Error 2 make[1]: Leaving directory ‘/home/me/Documents/GitHub/cpython’ make: *** [Makefile:752: profile-run-stamp] Error 2 make: Leaving directory ‘/home/me/Documents/GitHub/cpython’ smontanaro (Skip Montanaro) June 8, 2022, 11:55am 4 Again, works for me (switching from 3.11 branch to 3.10 branch): (python39) cpython% ./python Python 3.10.5+ (heads/3.10:9cc0afcb87, Jun 8 2022, 06:52:35) [Clang 10.0.0 ] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.version '3.10.5+ (heads/3.10:9cc0afcb87, Jun 8 2022, 06:52:35) [Clang 10.0.0 ]' I suggest you open an issue on GitHub and provide as many details as you can (platform, configure flags, etc) to help the experts figure out what’s wrong. mikecm (mike McLeod) June 8, 2022, 2:47pm 5 Did a sync to latest 3.12 and it worked!
However 3.10.5 didn’t: make -s -w then 2 warnings generated. /usr/bin/ld: libpython3.10.a: error adding symbols: file format not recognized clang-14: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [Makefile:601: python] Error 1 make: Leaving directory ‘/home/me/Documents/Python/Python-3.10.5’ make -d No need to remake target ‘libpython3.10.a’. Finished prerequisites of target file ‘python’.
Must remake target ‘python’. /usr/bin/clang -Xlinker -export-dynamic -o python Programs/python.o libpython3.10.a -lcrypt -ldl -lm -lm Putting child 0x5570d6d68f70 (python) PID 30363 on the chain. Live child 0x5570d6d68f70 (python) PID 30363 /usr/bin/ld: libpython3.10.a: error adding symbols: file format not recognized clang-14: error: linker command failed with exit code 1 (use -v to see invocation) Reaping losing child 0x5570d6d68f70 PID 30363 make: *** [Makefile:601: python] Error 1 Removing child 0x5570d6d68f70 PID 30363 from chain.
But how do I get a recompile of libpython3.10.a ? Is that even possible? I’ll hold off creating a issue right now.