title: Problem with C++ compiler on macOS (building cmake project)
body: <p>I have a 16inch MacBook pro with latest updates (macOS Catalina 10.15.2 (19C57)), the latest version of XCode and Command line tools for macOS (the tools being installed in the usual path /Library/Developer/CommandLineTools/).. Not sure if this is relevant to my issue or not, but I also have the latest version of JetBrains’s CLion installed on my machine (running without issues). </p>
  
  <p><strong>Here is the problem:</strong> When trying to build a project with cmake, the build FAILS, giving me this error message:</p>
  
  <pre><code>In file included from /Users/basavyr/Pipeline/DevWorkspace/Github/xrootd/bindings/python/src/PyXRootDFile.cc:25:
  In file included from /Users/basavyr/Pipeline/DevWorkspace/Github/xrootd/bindings/python/src/PyXRootD.hh:28:
  In file included from /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:38:
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:61:15: fatal error: 
        'string.h' file not found
  #include_next &lt;string.h&gt;
  1 error generated.
  error: command '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc' failed with exit status 1
  make[2]: *** [bindings/python/python_bindings] Error 1
  make[1]: *** [bindings/python/CMakeFiles/python_target.dir/all] Error 2
  make: *** [all] Error 2
  </code></pre>
  
  <p>and this is probably related to my C++ compiler not having the correct path to the include files. To see what the issue could be, I’ve made a simple C++ file and I tried to compile it.</p>
  
  <blockquote>
    <p>main.cpp</p>
  </blockquote>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;string&gt;
  #include &lt;cmath&gt;
  #include &lt;vector&gt;
  
  int main()
  {
      std::string name = "NAMEX";
      std::cout &lt;&lt; name;
  }
  </code></pre>
  
  <p>First, I tried with the usual “g++” and it worked just fine:</p>
  
  <pre><code>basavyr@Roberts-MacBook-Pro stringTestCLANG % g++ main.cpp 
  basavyr@Roberts-MacBook-Pro stringTestCLANG % ./a.out 
  NAMEX%                                                                                                                basavyr@Roberts-MacBook-Pro stringTestCLANG %
  </code></pre>
  
  <p>Then, I tried with <code>/Applications/Xcode.app/Contents/Developer/usr/bin/g++ main.cpp</code> and it worked just fine. 
  Checking the version of “g++” on my machine gives me this:</p>
  
  <pre><code>g++ -v
  Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
  Apple clang version 11.0.0 (clang-1100.0.33.17)
  Target: x86_64-apple-darwin19.2.0
  Thread model: posix
  InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
  </code></pre>
  
  <p>This is interesting, because I was expecting that the <em>default</em> compiler is installed in <code>/usr/bin/</code> instead. Going into that “InstalledDir” folder I saw that there is no “g++” binary, but only “clang++” and “c++”, so I tried to compile with both and it turns out that both compilers are giving the same error as the one in the project that I trying to build:</p>
  
  <pre><code>basavyr@Roberts-MacBook-Pro stringTestCLANG % /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ main.cpp
  In file included from main.cpp:1:
  In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
  In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
  In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:15:
  In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:505:
  In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string_view:176:
  In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:57:
  In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:642:
  In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:61:15: fatal error: 
        'string.h' file not found
  #include_next &lt;string.h&gt;
                ^~~~~~~~~~
  1 error generated.
  basavyr@Roberts-MacBook-Pro stringTestCLANG %
  </code></pre>
  
  <p>Since I also have Command Line Tools installed, I tried to compile with both “g++” and “clang++” from <code>/Library/Developer/CommandLineTools/usr/bin/</code> and the first one compiles successfully, while the second one throws the same error with regards to the string header file.</p>
  
  <pre><code>basavyr@Roberts-MacBook-Pro stringTestCLANG % /Library/Developer/CommandLineTools/usr/bin/c++ main.cpp
  In file included from main.cpp:1:
  In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iostream:38:
  In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ios:216:
  In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:15:
  In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string:505:
  In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string_view:176:
  In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__string:57:
  In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:642:
  In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cstring:61:
  /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
  #include_next &lt;string.h&gt;
                ^~~~~~~~~~
  1 error generated.
  </code></pre>
  
  <p>So, I assume that when I build that project with cmake, it is using one of these compilers (from the XCodeDefault.xctoolchain folder) and it has issues with the string header.</p>
  
  <p><strong>Q1:</strong> How can I solve this issue? <strong>Q2:</strong> And also, why does my “g++” installation directory points to this XCodeDefault.xctoolchain instead of “/usr/bin/’ or “/Applications/Xcode.app/Contents/Developer/usr/bin/”. Is there a way to change that in macOS?</p>
  
  <p>Thank you in advance</p>