解决 error: cannot run test program while cross compiling 问题的方案

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/hexf9632/article/details/102625696

交叉编译configure时候经常使用 --host 选项,但是在configure中有很多的测试程序是不可以在HOST上运行的,此时就有可能出现如下错误:

error: cannot run test program while cross compiling

类似的错误,我们可以使用下述方法。

1、使用cache file

报错如下:

checking abstract socket namespace... 
configure: error: cannot run test program while cross compiling

在configure中查找abstract socket,可以看到类似这样的结构:

echo "$as_me:$LINENO: checking abstract socket namespace" >&5
echo $ECHO_N "checking abstract socket namespace... $ECHO_C" >&6
if test "${ac_cv_have_abstract_sockets+set}" = set; then
  echo $ECHO_N "(cached) $ECHO_C" >&6

其中 ac_cv_have_abstract_sockets 是我们要查找的变量。执行如下命令即可解决:

/* cache文件可以任意命名,--host指定交叉编译的目的平台 */
# echo ac_cv_have_abstract_sockets=yes > xxx.cache
# ./configure --host=arm-linux --cache-file=xxx.cache

2、直接注释

编译barnyard2的时候出现如下错误:

checking for INADDR_NONE... configure: error: in `/root/barnyard2-master':
configure: error: cannot run test program while cross compiling

查看configure,相关内容如下:

# In case INADDR_NONE is not defined (like on Solaris)
have_inaddr_none="no"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for INADDR_NONE" >&5
$as_echo_n "checking for INADDR_NONE... " >&6; }
if test "$cross_compiling" = yes; then :
  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot run test program while cross compiling
See \`config.log' for more details" "$LINENO" 5; }
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>


int
main ()
{
	if (inet_addr("10,5,2") == INADDR_NONE);
	return 0;

	;
	return 0;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
  have_inaddr_none="yes"
else
  have_inaddr_none="no"
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  conftest.$ac_objext conftest.beam conftest.$ac_ext
fi

此处不像第一种方法中的例子一样,这边是使用cross_compoling变量来控制的,这个变量在很多地方都有使用,所以不好使用上述方法,目前我的解决方法是将该段全部注释或删掉,不去检查该项。


其他方案:
之前在网上有看到过解决方案是说找到下面这段,然后把have_inaddr_none=yes写入cache文件,再使用上述第一种方法:执行 #./configure --host=arm-linux --cache-file=xxx.cache,但是这种方法并不奏效。

if ac_fn_c_try_run "$LINENO"; then :
  have_inaddr_none="yes"
else
  have_inaddr_none="no"
fi

猜你喜欢

转载自blog.csdn.net/hexf9632/article/details/102625696
今日推荐