Issue 25229: distutils doesn't add "-Wl," prefix to "-R" on Linux if the C compiler isn't named 'gcc' (original) (raw)

On Exherbo, the main C/C++ compilers are named e.g. "x86_64-pc-linux-gnu-cc" and "x86_64-pc-linux-gnu-c++", and they are symlinks to either (usually) gcc or (rarely) clang.

Since distutils (in unixccompiler.py) is checking for the substring "gcc" or "g++" in the compiler name, this does not match our compiler - and the "-Wl," prefix is missing, resulting in link errors in some cases.

(We are particularly noticing this when doing gobject-introspection builds via cmake, where giscanner uses distutils to build the link command)

As far as I know, all major compilers on Linux require the -Wl, option to pass through linker options - clang actually interprets -R without -Wl, to mean something completely different. We are planning to locally patch distutils to have an additional condition to the gcc check, sys.platform[:5] == "linux" or self._is_gcc(compiler): in our distribution to work around the issue.

I'll attach patches once they're prepared, but I'd appreciate feedback about the problem.

I am seeing this with clang on linux. It breaks the building pyzmq. I'll concur with Calvin that using just "-R" is wrong in the first place. Some compiler may pass it directly to the linker. But even in the linker, interpreting "-R" as a rpath if the argument is a directory, is a legacy behavior. "-R" is supposed to be used to add remarks (see ld's man page). On linux it should just be "-Wl,-rpath" and it should work with all compilers.

Distutils is now deprecated (see PEP 632) and all tagged issues are being closed. From now until removal, only release blocking issues will be considered for distutils.

If this issue does not relate to distutils, please remove the component and reopen it. If you believe it still requires a fix, most likely the issue should be re-reported at https://github.com/pypa/setuptools