https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100017
--- Comment #68 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #57) > I don't see how the patch could be correct. > [...] > So, if CXX_FOR_TARGET starts with /, e.g. /opt/gcc-11.1/bin/g++ , then > the above will use dirname /opt/gcc-11.1/bin/g++ and set ac_dir to > /opt/gcc-11.1/bin > But with the proposed change, $RAW_CXX_FOR_TARGET will be > /opt/gcc-11.1/bin/g++ -nostdinc++ and dirname will fail miserably and not > set ac_dir to anything: > dirname /opt/gcc-11.1/bin/g++ -nostdinc++ > dirname: invalid option -- 'n' > Try 'dirname --help' for more information. Jakub's analysis is correct. If the cross compiler is found in PATH then the patch works OK. The configure output shows: checking where to find the target c++... pre-installed checking where to find the target c++ for libstdc++... pre-installed If you build with something like CXX_FOR_TARGET=/home/jwakely/gcc/aarch64/bin/aarch64-none-linux-gnu-g++ then configure shows: checking where to find the target c++... pre-installed in /home/jwakely/gcc/aarch64/bin checking where to find the target c++ for libstdc++... pre-installed in /home/jwakely/gcc/aarch64/bin But with the patch that prints an error: checking where to find the target c++... pre-installed in /home/jwakely/gcc/aarch64/bin checking where to find the target c++ for libstdc++... dirname: invalid option -- 'n' Try 'dirname --help' for more information. pre-installed in I don't think that actually causes a problem though. The build still works. The dirname command is only used to print the result during configure. It's not great though. If we do this instead, then we don't have that problem: diff --git a/Makefile.in b/Makefile.in index 79c77fccf0f..ada25b8f11b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -329,7 +329,7 @@ BASE_TARGET_EXPORTS = \ RAW_CXX_TARGET_EXPORTS = \ $(BASE_TARGET_EXPORTS) \ CXX_FOR_TARGET="$(RAW_CXX_FOR_TARGET)"; export CXX_FOR_TARGET; \ - CXX="$(RAW_CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; + CXX="$(RAW_CXX_FOR_TARGET) -nostdinc++ $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; NORMAL_TARGET_EXPORTS = \ $(BASE_TARGET_EXPORTS) \ diff --git a/Makefile.tpl b/Makefile.tpl index ef58fac2b9a..fc10c7a771d 100644 --- a/Makefile.tpl +++ b/Makefile.tpl @@ -332,7 +332,7 @@ BASE_TARGET_EXPORTS = \ RAW_CXX_TARGET_EXPORTS = \ $(BASE_TARGET_EXPORTS) \ CXX_FOR_TARGET="$(RAW_CXX_FOR_TARGET)"; export CXX_FOR_TARGET; \ - CXX="$(RAW_CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; + CXX="$(RAW_CXX_FOR_TARGET) -nostdinc++ $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; NORMAL_TARGET_EXPORTS = \ $(BASE_TARGET_EXPORTS) \ I think that will mean we get -nostdinc++ twice for build==host builds, but that's harmless. The other reason I'm unsure about adding -nostdinc++ to RAW_CXX_FOR_TARGET is that it's also used for building other target libs, specifically libsanitizer and libvtv. I think it's correct for them too.