[英]gcc: ignore unrecognized option
Is there a way to make gcc ignore an invalid option, instead of dying with "unrecongized option"? 有没有办法让gcc忽略一个无效的选项,而不是死于“未识别的选项”? Reason is I want to use an option only available in later versions of gcc (-static-libstdc++), but it should also compile on older compilers.
原因是我想使用仅在更高版本的gcc(-static-libstdc ++)中可用的选项,但它也应该在较旧的编译器上编译。 I could check for gcc version in the makefile but it is a bit ugly.
我可以在makefile中检查gcc版本,但它有点难看。
no, but you can set the flags based on the gcc version as follows: 不,但您可以根据gcc版本设置标志,如下所示:
version=`gcc --version | head -1 | cut -d ' ' -f3`
if [ `echo -e "$version\n4.6.1" | sort -V -C; echo $?` == 0 ]; then
flags = -static-libstdc++;
fi
gcc $flags ...
(Disclaimer: I'm not sure which version first uses static-libstdc++, 4.6.1 is just a guess). (免责声明:我不确定哪个版本首先使用static-libstdc ++,4.6.1只是猜测)。
John 约翰
You can run gcc and check if it accepts the flag: 您可以运行gcc并检查它是否接受该标志:
STATIC_LIBCPP_FLAG := $(shell if gcc -static-libstdc++ --version 2>&1 | grep -q 'unrecognized option'; then true; else echo -static-libstdc++; fi)
CFLAGS += $(STATIC_LIBCPP_FLAG)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.