<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:dimitry@andric.com" title="Dimitry Andric <dimitry@andric.com>"> <span class="fn">Dimitry Andric</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Fail to build LLVM due to cmath on macOS 10.13"
   href="https://bugs.llvm.org/show_bug.cgi?id=52575">bug 52575</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>dimitry@andric.com
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Fail to build LLVM due to cmath on macOS 10.13"
   href="https://bugs.llvm.org/show_bug.cgi?id=52575#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Fail to build LLVM due to cmath on macOS 10.13"
   href="https://bugs.llvm.org/show_bug.cgi?id=52575">bug 52575</a>
              from <span class="vcard"><a class="email" href="mailto:dimitry@andric.com" title="Dimitry Andric <dimitry@andric.com>"> <span class="fn">Dimitry Andric</span></a>
</span></b>
        <pre>This error occurs because you are compiling a C++ program, and are using
"-isystem
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include",
which puts this directory at the front of your include search dirs, *before*
the libc++ include directory.

This will not work correctly, and you should probably just stop adding
-isystem. But if that is not possible for other reasons, you should also add
the libc++ include directory *before* the regular include directory, i.e. do
something like:

-isystem ${SDKDIR}/usr/include/c++/v1 -isystem ${SDKDIR}/usr/include

(Assuming here that
SDKDIR="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk")

How this happens is as follows. By default, if you compile a C++ program, clang
sets up the include search dirs similar to:

#include <...> search starts here:
 /usr/local/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
(framework directory)

Any header such as <cmath> or <math.h> will therefore be found *first* in the
libc++ include directory, ${SDKDIR}/usr/include/c++/v1. Whenever libc++ wants
to use the C version of <math.h>, it will include it using
#include_next<math.h>, which attempts to find math.h from the *next* path in
the search directory list.

So normally, including <cmath> goes like:
* #include <cmath>       -> finds ${SDKDIR}/usr/include/c++/v1/cmath
* #include <math.h>      -> finds ${SDKDIR}/usr/include/c++/v1/math.h (this is
a wrapper header)
* #include_next <math.h> -> finds ${SDKDIR}/usr/include/math.h

Now if you add -isystem ${SDKDIR}/usr/include to your compilation, the include
search dirs will look like:

#include <...> search starts here:
 /usr/local/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/include

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
(framework directory)

I.e., ${SDKDIR}/usr/include is now before ${SDKDIR}/usr/include/c++/v1, and
then including <cmath> goes like:
* #include <cmath>       -> still finds ${SDKDIR}/usr/include/c++/v1/cmath, as
before
* #include <math.h>      -> finds ${SDKDIR}/usr/include/math.h, the plain C one
and *not* the wrapper header
* there won't be any #include_next <math.h> now since the plain C version does
not do that
* back in <cmath>, several "using" directives will now fail since the libc++
math.h wrapper was not included first

So the conclusion of this story is: if you really must set your own system
include paths using -isystem, that is fine, but you *must* also set the C++
include paths correctly, and in the right order, not only the plain C include
paths.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>