问题描述
Autoconf的AC_COMPILE_IFELSE
在不同的编译器(例如Sun的C ++编译器和IBM的xlC编译器)下误判了我们的功能. AC_COMPILE_IFELSE
似乎可以检查返回值,但是某些编译器不会费心设置它或将其设置为意外值.稍后,我们将使用不可用的选项.
Autoconf's AC_COMPILE_IFELSE
is misdetecting features for us under different compilers, like Sun's C++ compiler and IBM's xlC compiler. AC_COMPILE_IFELSE
appears to check return values, but some compilers don't bother to set it or set it to unexpected values. Later, we use options that are not available.
在非Autoconf构建脚本中,我使用"fatal|error|illegal|unrecognized|not found|not exist"
来检测编译器或链接器投诉.它比仅检查$?
更强大.测试如下:
In my non-Autoconf build scripts I use "fatal|error|illegal|unrecognized|not found|not exist"
to detect a compiler or linker complaint. It is more robust than just checking $?
. The test looks like:
# infile and outfile are temp files that allow testing a feature
SH_ERROR=$($CXX -Wl,--enable-new-dtags -o "$outfile" "$infile" 2>&1 | $EGREP -i -c -E 'fatal|error|illegal|unrecognized|not found|not exist')
if [[ "$SH_ERROR" -eq "0" ]]; then
CXXFLAGS+="-Wl,--enable-new-dtags"
fi
AC_COMPILE_IFELSE
的Autoconf文档位于 6.4运行编译器,但没有讨论主题.实际上,该文档甚至没有定义AC_COMPILE_IFELSE
成功[成功]"的含义.
The Autoconf documentation for AC_COMPILE_IFELSE
is at 6.4 Running the Compiler, but it does not discuss the subject matter. In fact, the document does not even define what it means for AC_COMPILE_IFELSE
to be "success[ful]".
我的第一个问题是,编译器的返回值是否在某处标准化?
My first question is, are compiler return values standardized somewhere?
我的第二个问题是,Autoconf用什么来确定成功"?
My second question is, what does Autoconf use to determine "success"?
我的第三个问题是,我们如何在Autoconf中做同样的事情?除了AC_COMPILE_IFELSE
之外还有其他东西要使用吗?
My third question is, how do we do the same in Autoconf? Is there something else to use besides AC_COMPILE_IFELSE
?
一个相关的问题是(基于Stefan的答案),如何使Autoconf使用改进的AC_COMPILE_IFELSE
?是否可以取消定义当前AC_COMPILE_IFELSE
并将其定义为更强大的版本?
A related question is (based on Stefan's answer), how do we get Autoconf to use an improved AC_COMPILE_IFELSE
? Is it possible to undef the current AC_COMPILE_IFELSE
and define it to the more robust version?
谢谢.
推荐答案
除了可以退出代码的所有程序的明显标准之外,我非常确定没有标准来定义针对任何语言的编译器应返回什么0
表示成功以及其他所有失败,请参见函数的posix上的pos ="/:pubs.opengroup.org/onlinepubs/000095399/functions/exit.html" rel:
I'm pretty sure there is no standard defining what compilers for any language should return, apart from the obvious standard for all programs that exit code 0
means success and everything else failure, see posix on the exit
function:
最新的autoconf版本是2.69(从2012年开始),尽管某些情况可能已更改,但我将基于此答案.
The latest autoconf release is 2.69 (from 2012), and although some things might have changed, I'm going to base my answer on it.
AC_COMPILE_IFELSE
成功,如果编译器具有成功的退出代码(即0
)并且目标文件不为空(test -s conftest.$ac_objext
;则为在运行编译器之前将其删除).如果 AC_LANG_WERROR
用于当前语言,它还可以确保编译器的stderr
输出为空(除了 shell跟踪日志行).
AC_COMPILE_IFELSE
is successful, iff the compiler has a successful exit code (i.e. 0
) and the object file is not empty (test -s conftest.$ac_objext
; it is removed before running the compiler). If AC_LANG_WERROR
was used for the current language it also makes sure the stderr
output of the compiler is empty (apart from shell trace log lines).
请记住,尽管autoconf来源看起来像魔术,但它们并不是-您可以构建自己的宏,只要您知道自己想要它们做什么即可: www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Generic-Compiler-Characteristics.html#index-AC_005fLANG_005fWERROR-833"rel =" nofollow noreferrer> AC_LANG_WERROR
是一个选项,除了告诉供应商吸吮并修复废话之外.
Keep in mind, that although the autoconf sources look like magic, they are not - you can build your own macros as long as you know what you want them to do :) But maybe AC_LANG_WERROR
is an option, apart from telling the vendor to suck it and fix their crap.
我不是AC_LANG_WERROR
的粉丝:几年前,我不得不在多体系结构的系统上使用/etc/ld.so.preload
来解决flashplayer的问题,并且从另一个体系结构运行二进制文件总是会打印错误,无法加载它,尽管它没有什么问题-AC_LANG_WERROR
在这种环境下严重损坏
I'm not a fan of AC_LANG_WERROR
: I had to use /etc/ld.so.preload
on a multiarch system to fix problems with flashplayer some years ago, and running binaries from the other arch would always print an error it couldn't load it, although there was nothing wrong with it - AC_LANG_WERROR
breaks horribly in such environment
作为自定义编译检查宏的示例,请查看以下内容:
As an example of a custom compile check macro take a look at this:
# MY_COMPILE_CLEAN_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
# ---------------------------------------------------------------
# Try to compile PROGRAM.
AC_DEFUN([MY_COMPILE_CLEAN_IFELSE],
[AC_REQUIRE([AC_PROG_EGREP])
AC_COMPILE_IFELSE([$1],[retval=0
if $EGREP -i -c -E 'fatal|error|unrecognized|not found|not exist' conftest.err >/dev/null; then retval=1; fi
],[retval=1])
AS_IF([test $retval = 0],[$2],[$3])])
conftest.err
在完成AC_COMPILE_IFELSE
之后被删除,因此您需要在内部操作中对其进行检查.
conftest.err
is deleted after AC_COMPILE_IFELSE
is done, so you need to check it in the inner actions.
这篇关于更强大的AC_COMPILE_IFELSE功能测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!