Preliminary research in embedded Linux compiler dhcp error "can not check for file existence when cross compiling" the

Foreword, the origin of this writing

      In a recent study Wei Dongshan embedded training video (3 project combat the USB camera monitoring), when the code to configure dhcp source error: can not check for file existence when cross compiling. Although given in the video tutorial approach "./configure --host = arm-linux" then add "ac_cv_file__dev_random = yes", to solve the problem. But when you see the configure file in the same day the book text, invariably many wonder: Is it in order to write a dhcp such a program, but also to write so obscure configure the code? dhcp author of this grand do it?

      After the study, and finally we found the original of this document is not written directly configure it by hand, but by this tool autoconf generated based autoconf.ac or autoconf.in automatically. While the latter is manually written out. The purpose of using autoconf of the program is to enable us to write out (such as this dhcp) can be easily ported to a variety of unix (or class unix) on the system.

      Conclusion Although very simple, but to clarify the circumstances surrounding them, or spend a lot of time. But I think it is worth it, because the understanding of the ins and outs, they possess the routine. After the encounter a similar problem, you can judge the whole, a pretty good idea, but do not have to like headless flies like crazy.

First, the experimental environment

1.1 virtual machine environment

a) Vmware printed books: Vmware Workstation 12.5.7

b) Ubuntu Version: 9.10

c) kernel version: 2.6.31.14

1.2 development environment board

1.2.1 Hardware

Development Board: Hundred Questions net JZ2440 development board

wifi card: RT3070

1.2.2 Software

a) kernel version: 3.4.2

b) toolchain version:

    arm-linux-gcc 4.3.2

c) dhcp version: 4.2.5-P1

Second, cross-compiler dhcp, when configure, given the information and the process of resolving abbreviated

1、./configure  --host=arm-linux

  报错:configure:error: cannot check for file existence when cross compiling

   The investigation is configure file line7695:

   if test "${ac_cv_file__dev_random+set}" = set; then

       echo $ECHO_N "(cached) $ECHO_C" >&6

   else

        test "$cross_compiling" = yes &&

        { { echo "$as_me:$LINENO: error: cannot check for file existence when cross compiling" >&5

        echo "$as_me: error: cannot check for file existence when cross compiling" >&2;}

        { (exit 1); exit 1; }; }

    Solution: behind ./configure --host = arm-linux plus: ac_cv_file__dev_random = yes

2, make, given:

    configure: error: cannot check for file existence when cross compiling

    In configure.log, find this line:

    configure:22156: error: cannot check for file existence when cross compiling

    According to this prompt, in configure: 22156, found:

    if eval \${$as_ac_File+:} false; then :

         $as_echo_n "(cached) " >&6

    else

         test "$cross_compiling" = yes &&

         as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5

    Defined in the $ as_ac_File: bind / bind-9.8.4-P2 / configure: 22149:

    as_ac_File=`$as_echo "ac_cv_file_$devrandom" | $as_tr_sh`

    Solution: Modify bind / bind-9.8.4-P2 / Makefile:

    Line55: ./configure  --host=arm-linux  ac_cv_file__dev_random=yes

Third, the principle of Exploration

     In fact, / configure file line7695 that part of the bible, it is autoconf automatically generated based on ./configure.ac:

 Line536:
      AC_CHECK_FILE(/dev/random,
          AC_DEFINE([HAVE_DEV_RANDOM], [1],
              [Define to 1 if you have the /dev/random file.]))

      Similar, bind / bind-9.8.4-P2 / configure the period of bible, it is autoconf according to bind / bind-9.8.4-P2 / configure.in automatically generated:

line1087 :
      AC_CHECK_FILE($devrandom,
			AC_DEFINE_UNQUOTED(PATH_RANDOMDEV,
			     "$devrandom"),)

      The role of AC_CHECK_FILE (file, [action-if-found], [action-if-not-found]) is, simply, is to check the $ devrandom representative file exists, if the implementation of action-if-found, otherwise execute action-if-not-found.

      The realization of the code macro /usr/share/autoconf/autoconf/general.m4, line 2764

      The intermediate code of a large section, is variable about the cache, in order to accelerate the search result object (see https://www.gnu.org/software/autoconf/manual/autoconf-2.64/html_node/Cache-Variable- Variable-Cache-# Names.html Names )

Note: To enable the cache variables need to be passed in the implementation of the configure command -C or --config-cache option, can now be found in the file config.cache configure the same level directory for storing all cache variables, variable cache in memory for shell variables when configure start, AC_INIT calls AC_CACHE_LOAD from config.cache read into the shell variable. When configure quit, calls AC_CHECK_FILE stored in config.cache file). cache variable name must contain "_cv_", which means the cache value, if the lack of it, then it can not be a cache.

      Roughly interpretation of this macro is as follows (assuming that recall scenes that bind / bind-9.8.4-P2 / configure.in in the line1087: AC_CHECK_FILE (/ dev / random, AC_DEFINE_UNQUOTED (PATH_RANDOMDEV, "$ devrandom"),):

AC_DEFUN ([AC_CHECK_FILE], 

[AC_DIAGNOSE ([Cross], 

     [CAN not the Check for File Existence the when Cross Compiling]) DNL # print some information
 
AS_VAR_PUSHDEF ([ac_File], [ac_cv_file_ $ 1]) DNL # define a temporary macro ac_File, expand the result is ac_cv_file__dev_random
 
AC_CACHE_CHECK ([for $ 1], [ac_File],   # find whether there ac_cv_file__dev_random the cache variable
 
[the Test " $ cross_compiling " = yes &&     # if there is no check $ cross_compiling whether yes
 
  AC_MSG_ERROR ([CAN not the check for File Existence the when Compiling Cross]) # is the show can not check for ..., then exit; 

iF the test -r " $ 1 "; the then # otherwise perform test -r "$ 1" test / dev / random is readable
 
  AS_VAR_SET ([ac_File] ,[Yes]) # is the cache is set variable ac_cv_file__dev_random = yes

Else 

  AS_VAR_SET ([ac_File], [NO]) # otherwise set cache variable ac_cv_file__dev_random = NO
 
Fi]) 

AS_VAR_IF ([ac_File], [Yes], [$ 2], [$. 3]) # If cache variable ac_cv_file__dev_random = yes, execute AC_DEFINE_UNQUOTED (PATH_RANDOMDEV, "$ devrandom")
 
AS_VAR_POPDEF ([ac_File]) DNL # cancel temporary macro ac_File
 
]) # AC_CHECK_FILE
      It can be seen, AC_CHECK_FILE when ac_cv_file__dev_random not find this cache variable, first determines whether the current cross-compilation, is the show can not check for file existence when cross compiling, then exit.

      So the question is: why, when the situation encountered AC_CHECK_FILE cross compiler, is there such a behavior characteristic of it? Explained the official website is:

Be aware that, like most Autoconf macros, they test a feature of the host machine, and therefore, they die when cross-compiling.

      This means that: AC_CHECK_FILE only if the file is used to check the host (instead of the target machine) on the present. So when faced with the situation of cross-compiler, it will find no way out!

      Presumably this interpretation also makes sense, since configure is running on the host, and that of course can not go to check the files on the target machine. But in that case, back to the origin of the problem: Why is configure dhcp to check the / dev / random this document? I guess it should be compiled since the final out of the program need to use the / dev / random? (Otherwise it would not be Scrapped?)

      If so, then there is / dev / random as long as the target machine (by "ls / dev | grep random" check down do exist), and that even skip this check, it should have no impact.

      As a result, a further question is: how to make configure to skip this check?

      The solution is: as long as the mandatory ac_cv_file__dev_random this cache variable is set to yes you can, specifically, there are two options:

      Measures 1) in accordance with the practice of the video, modified bind / Makefile:

                Line55: ./configure  --host=arm-linux  ac_cv_file__dev_random=yes

      Option 2) may be slightly better versatility

      Since ac_cv_file__dev_random cache is variable, and ./configure.ac and bind / bind-9.8.4-P2 / configure.in have access to this variable, and that between these two documents is not some kind of mechanism can be used to share this variable it? The answer is yes. On the official website of autoconf ( https://www.gnu.org/software/autoconf/manual/autoconf-2.64/html_node/Cache-Files.html#Cache-Files ) can be found in 7.4.2 Cache Files, About cache files, there are so many words:

When configure calls configure scripts in subdirectories, it uses the --cache-file argument so that they share the same cache。

That is, when the configure call subdirectories in the parent directory in the configure, can be passed by the former to the latter --cache-file = xxx to the latter shared Cache .

      Thus, for the problem at the beginning of this article configure error, the first two kinds of solutions are:

Step1) when performing configure the root directory, add the -C option:

./configure  --host=arm-linux  ac_cv_file__dev_random=yes -C

Step2) modify the bind / Makefile:

Line55: ./configure  --host=arm-linux --disable-kqueue --cache-file=../../config.cache

Fourth, Postscript

      About autoconf, if you want to get to the bottom, it is a pit. But for this project, we can only ask dhcp transplanted to the development board, and run up to, do not need to start from scratch to write a dhcp. So, we are only need autoconf get an idea on the line. This article can be used as a signpost, so that in the future the road ahead of the encounter the same pit, and will not rip off circle.

V. References

1) Wei Dongshan "embedded linux video tutorial _ Phase III combat the USB camera surveillance."

2) GNU autoconf official website Manual ( https://www.gnu.org/software/autoconf/manual )

Guess you like

Origin www.cnblogs.com/normalmanzhao2003/p/11517290.html