title: How to use an AC_CHECK_HEADER header in an AC_COMPILE_IFELSE program
body: <p>I'm performing a header check for a non-standard <code>&lt;x86intrin.h&gt;</code> header provided by Clang and GCC. Other compilers follow Intel and use <code>&lt;immintrin.h&gt;</code>:</p>
  
  <pre><code>AC_CHECK_HEADER([x86intrin.h])
  </code></pre>
  
  <p>Autotools finds it on the Linux test systems:</p>
  
  <pre><code>checking x86intrin.h usability... yes
  checking x86intrin.h presence... yes
  checking for x86intrin.h... yes
  </code></pre>
  
  <p>I then use it in a test:</p>
  
  <pre><code>CXXFLAGS="-mrdseed"
  XXX_PROGRAM="#include &lt;immintrin.h&gt;
     #ifdef HAVE_X86INTRIN_H
     # include &lt;x86intrin.h&gt;
     #endif
     int main(int argc, char** argv) {
        unsigned int x;
        return _rdseed32_step(&amp;x);
     }"
  
  AC_MSG_CHECKING([if $CXXNAME supports $CXXFLAGS])
  AC_COMPILE_IFELSE(
     [AC_LANG_SOURCE([$XXX_PROGRAM])],
     [AC_MSG_RESULT([yes])],
     [AC_MSG_RESULT([no])]
  )
  </code></pre>
  
  <p>The test fails:</p>
  
  <pre><code>checking if g++ supports -mrdseed... no
  </code></pre>
  
  <p>The machine has the feature and the compiler supports it. Looking at <code>condefs.h</code> from <code>config.log</code> shows <code>HAVE_X86INTRIN_H</code> is not being set as expected.</p>
  
  <p>The manual shows how to use a header resulting from a check at <a href="https://www.gnu.org/software/autoconf/manual/autoconf-2.62/html_node/Generic-Headers.html" rel="nofollow noreferrer">5.6.3 Generic Header Checks</a>. I think I am doing roughly the same thing:</p>
  
  <pre><code>AC_CHECK_HEADERS([foo.h])
  AC_CHECK_HEADERS([bar.h], [], [],
  [#ifdef HAVE_FOO_H
   # include &lt;foo.h&gt;
   # endif
  ])
  </code></pre>
  
  <p>How do I use an <code>AC_CHECK_HEADER</code> header in an <code>AC_COMPILE_IFELSE</code> program?</p>
  
  <hr>
  
  <p>Here is my test driver:</p>
  
  <pre><code>$ cat test.cxx
  #include &lt;immintrin.h&gt;
  #ifdef HAVE_X86INTRIN_H
  # include &lt;x86intrin.h&gt;
  #endif
  int main(int argc, char** argv) {
      unsigned int x;
      return _rdseed32_step(&amp;x);
  }
  
  $ g++ -mrdseed test.cxx -o test.exe
  test.cxx: In function ‘int main(int, char**)’:
  test.cxx:7:12: error: ‘_rdseed32_step’ was not declared in this scope
       return _rdseed32_step(&amp;x);
              ^~~~~~~~~~~~~~
  test.cxx:7:12: note: suggested alternative: ‘_rdrand32_step’
       return _rdseed32_step(&amp;x);
              ^~~~~~~~~~~~~~
              _rdrand32_step
  
  $ g++ -DHAVE_X86INTRIN_H -mrdseed test.cxx -o test.exe
  $ ./test.exe
  $
  </code></pre>
  
  <hr>
  
  <p>Here is the distro and compiler:</p>
  
  <pre><code>$ lsb_release -a
  LSB Version:    :core-4.1-amd64:core-4.1-noarch
  Distributor ID: Fedora
  Description:    Fedora release 28 (Twenty Eight)
  Release:        28
  
  $ g++ --version
  g++ (GCC) 8.1.1 20180712 (Red Hat 8.1.1-5)
  </code></pre>
  
  <hr>
  
  <p>Here are the relevant parts from <code>config.log</code>:</p>
  
  <pre><code>configure:17624: checking if g++ supports -mrdseed
  configure:17631: g++ -o conftest -mrdseed   conftest.cpp  &gt;&amp;5
  conftest.cpp: In function 'int main(int, char**)':
  conftest.cpp:38:17: error: '_rdseed32_step' was not declared in this scope
            return _rdseed32_step(&amp;x);
                   ^~~~~~~~~~~~~~
  conftest.cpp:38:17: note: suggested alternative: '_rdrand32_step'
            return _rdseed32_step(&amp;x);
                   ^~~~~~~~~~~~~~
                   _rdrand32_step
  configure:17631: $? = 1
  configure: failed program was:
  | /* confdefs.h */
  | #define PACKAGE_NAME "Crypto++"
  | ...
  | #define STDC_HEADERS 1
  | #define HAVE_SYS_TYPES_H 1
  | #define HAVE_SYS_STAT_H 1
  | #define HAVE_STDLIB_H 1
  | #define HAVE_STRING_H 1
  | #define HAVE_MEMORY_H 1
  | #define HAVE_STRINGS_H 1
  | #define HAVE_INTTYPES_H 1
  | #define HAVE_STDINT_H 1
  | #define HAVE_UNISTD_H 1
  | #define HAVE_DLFCN_H 1
  | #define LT_OBJDIR ".libs/"
  | ...
  | /* end confdefs.h.  */
  | #include &lt;immintrin.h&gt;
  |       #ifdef HAVE_X86INTRIN_H
  |       # include &lt;x86intrin.h&gt;
  |       #endif
  |       int main(int argc, char** argv) {
  |          unsigned int x;
  |          return _rdseed32_step(&amp;x);
  |       }
  configure:17645: result: no
  </code></pre>