Clang without GCC or MSVC - c++

I'd like to use clang without GCC on Linux and without MSVC on Windows. My understanding is that this wasn't possible in the past due to:
A LLVM linker wasn't available.
A compatible STL wasn't available.
However, my impression what that this should be possible with v8.0.0 as there is now a viable linker and a compatible STL library.
Unfortunately, I get different errors on Linux and Windows when exercising this scenario (see more info below).
Can you help me out with this? Unfortunately, I've found it a bit challenging to find a definitive answer through various searches.
Thanks for the help!
Test Code: test.cpp
#include <vector>
#include <iostream>
int main(void) {
std::vector<int> const v{ 1, 2, 3 };
std::cout << "Hello world\n";
std::cout << v[0] << "\n";
return 0;
}
Linux output
The following output is from Windows Subsystem for Linux, but the behavior is the same on a proper Linux install.
clang -v /mnt/c/Temp/test.cpp -I/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8.0.1
"/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/bin/clang-8" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0 -I /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /mnt/c/Code/v3/Common/cpp/Clang/8 -ferror-limit 19 -fmessage-length 200 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/test-284194.o -x c++ /mnt/c/Temp/test.cpp -faddrsig
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1
/usr/local/include
/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0/include
/usr/include
End of search list.
In file included from /mnt/c/Temp/test.cpp:1:
In file included from /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1/vector:273:
/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1/__config:206:12: fatal error: 'features.h' file not found
# include <features.h>
^~~~~~~~~~~~
1 error generated.
Windows Output
clang -v c:\temp\test.cpp
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\bin
clang: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt [-Wmsvc-not-found]
"C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.11.0 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -momit-leaf-frame-pointer -v -resource-dir "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\lib\\clang\\8.0.0" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\lib\\clang\\8.0.0\\include" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\include\\c++\\v1" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Common\\Libraries\\C++\\Catch2\\v2.7.0" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Common\\Libraries\\C++\\GSL\\v2.0.0\\include" -fdeprecated-macro -fdebug-compilation-dir "C:\\Code\\v3\\Common\\cpp\\Clang\\8" -ferror-limit 19 -fmessage-length 200 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o "C:\\Users\\brownell\\AppData\\Local\\Temp\\test-9329b0.o" -x c++ "c:\\temp\\test.cpp" -faddrsig
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\lib\clang\8.0.0\include
C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1
C:\Code\v3\Common\cpp\Common\Libraries\C++\Catch2\v2.7.0
C:\Code\v3\Common\cpp\Common\Libraries\C++\GSL\v2.0.0\include
End of search list.
In file included from c:\temp\test.cpp:1:
In file included from C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\vector:274:
In file included from C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\iosfwd:96:
C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
^~~~~~~~~
1 error generated.

For linux
On linux clag will default to using gnu's implementation of the standard library which is libstdc++. To use llvm's implementation - libc++ - you first need to install it. On ubuntu, for instance: sudo apt install libc++-9-dev libc++abi-9-dev. You might need to add the apple repos. Follow these instructions for more systems and latest versions. Then you need to explicit specify it when compiling: -stdlib=libc++. Please see https://libcxx.llvm.org/docs/UsingLibcxx.html
For linking install lld (sudo apt install lld-9) then specify it when compiling with -fuse-ld=lld

Related

Using clang-11 to cross compile for aarch64-linux-gnu on x86-64 error: 'bits/c++config.h' file not found

I am trying to use clang-11 to cross compile a c++ file to aarch-linux-gnu, from my host machine which is x86-64.
Here's the command :
clang-11 -v -target aarch64-linux-gnu -B/usr/aarch64-linux-gnu/lib -march=armv8.5-a+memtag -fsanitize=memtag test_mte.cpp -static
But, I run into this error:
In file included from /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/stdlib.h:36: /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/cstdlib:41:10: fatal error: 'bits/c++config.h' file not found #include <bits/c++config.h>
I have installed the packages gcc-multilib g++-multilib binutils-aarch64-linux-gnu libc6-arm64-cross libc6-dev-arm64-cross crossbuild-essential-arm64 gcc-aarch64-linux-gnu
How can I resolve this error?
Full Output:
Here's the full output of the clang-11 command:
`Debian clang version 11.0.1-2~bpo10+1
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc-cross/aarch64-linux-gnu/8
Selected GCC installation: /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8
Candidate multilib: .;#m64
Selected multilib: .;#m64
"/usr/lib/llvm-11/bin/clang" -cc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test_mte.cpp -static-define -mrelocation-model static -mframe-pointer=non-leaf -fmath-errno -fno-rounding-math -mconstructor-aliases -target-cpu generic -target-feature +neon -target-feature +v8.5a -target-feature +mte -target-abi aapcs -fallow-half-argum
ents-and-returns -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib/llvm-11/lib/clang/11.0.1 -internal-isystem /usr/bi
n/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8 -internal-isystem /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../..
/include/aarch64-linux-gnu/c++/8 -internal-isystem /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/aarch64-linux-gnu/c++/8
-internal-isystem /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/backward -internal-isystem /usr/local/include -in
ternal-isystem /usr/lib/llvm-11/lib/clang/11.0.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdepreca
ted-macro -fdebug-compilation-dir /home/aditi712/mte_Stuff -ferror-limit 19 -fsanitize=memtag -fno-signed-char -fgnuc-version=4.2.1 -fcxx-ex
ceptions -fexceptions -fcolor-diagnostics -faddrsig -o /tmp/test_mte-836487.o -x c++ test_mte.cpp
clang -cc1 version 11.0.1 based upon LLVM 11.0.1 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/aarch64-linux-gnu/c++/8"
ignoring nonexistent directory "/usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/aarch64-linux-gnu/c++/8"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8
/usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/backward
/usr/local/include
/usr/lib/llvm-11/lib/clang/11.0.1/include
/usr/include
End of search list.
In file included from test_mte.cpp:7:
In file included from /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/stdlib.h:36:
/usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/cstdlib:41:10: fatal error: 'bits/c++config.h' file not found
#include <bits/c++config.h>`
It seems to me that clang is asking some gcc about system include paths, and this process fails (for some reason), leading to inclusion of host headers.
Here is a solution that helped me:
https://askubuntu.com/questions/947954/wrong-default-include-directories-for-clang-cross-compile
Basically you provide all system includes on your own. In our case (arm64), for me this boiled down to these flags:
-nostdinc++
-cxx-isystem /usr/aarch64-linux-gnu/include/c++/10/`
-cxx-isystem /usr/aarch64-linux-gnu/include/c++/10/aarch64-linux-gnu/
-isystem /usr/aarch64-linux-gnu/include

Kaleidoscope Chapter 8 linker command failed with exit code 1143

I am new to LLVM and wanted to experiment with the Kaleidoscope example. My
PC is a Windows 64 bit system. I managed to build LLVM from source with
CMake. I managed to build the examples of Kaleidoscope with Visual Studio
15 2017 from the .vcxproj file. The built toy.exe from chapter 8 runs well
from the command line and I could enter the function definition for average
as in the tutorial. toy wrote output.o to D:\llvm.bld\Debug\bin.
However, when I would like to compile and link the main.cpp as given in the
tutorial I get:
clang++.exe: error: linker command failed with exit code 1143 (use -v to
see invocation).
The full verbose output is copied below. How do you compile and link
main.cpp and output.o on a Windows 64 bit PC?
Greetings,
Ad Huikeshoven
D:\llvm.bld\Debug\bin>clang++ main.cpp output.o -o main -v
clang version 7.0.0 (tags/RELEASE_700/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\LLVM\bin
"D:\LLVM\bin\clang++.exe" -cc1 -triple
x86_64-pc-windows-msvc19.16.27025 -emit-obj -mrelax-all
-mincremental-linker-compatible -disable-free -disable-llvm-verifier
-discard-value-names -main-file-name main.cpp -mrelocation-model pic
-pic-level 2 -mthread-model posix -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info
-debugger-tuning=gdb -momit-leaf-frame-pointer -v -resource-dir
"D:\LLVM\lib\clang\7.0.0" -internal-isystem
"D:\LLVM\lib\clang\7.0.0\include" -internal-isystem
"D:\VisualStudio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include"
-internal-isystem "D:\Windows Kits\10\Include\10.0.17763.0\ucrt"
-internal-isystem "D:\Windows Kits\10\include\10.0.17763.0\shared"
-internal-isystem "D:\Windows Kits\10\include\10.0.17763.0\um"
-internal-isystem "D:\Windows Kits\10\include\10.0.17763.0\winrt"
-fdeprecated-macro -fdebug-compilation-dir "D:\llvm.bld\Debug\bin"
-ferror-limit 19 -fmessage-length 120 -fno-use-cxa-atexit -fms-extensions
-fms-compatibility -fms-compatibility-version=19.16.27025 -std=c++14
-fdelayed-template-parsing -fobjc-runtime=gcc -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o
"C:\Users\Ad\AppData\Local\Temp\main-884d07.o" -x c++ main.cpp
clang -cc1 version 7.0.0 based upon LLVM 7.0.0 default target
x86_64-pc-win32
#include "..." search starts here:
#include <...> search starts here:
D:\LLVM\lib\clang\7.0.0\include
D:\VisualStudio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include
D:\Windows Kits\10\Include\10.0.17763.0\ucrt
D:\Windows Kits\10\include\10.0.17763.0\shared
D:\Windows Kits\10\include\10.0.17763.0\um
D:\Windows Kits\10\include\10.0.17763.0\winrt
End of search list.
"D:\VisualStudio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\link.exe"
-out:main -defaultlib:libcmt
"-libpath:D:\VisualStudio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\lib\x64"
"-libpath:D:\Windows Kits\10\Lib\10.0.17763.0\ucrt\x64"
"-libpath:D:\Windows Kits\10\Lib\10.0.17763.0\um\x64" -nologo
"C:\Users\Ad\AppData\Local\Temp\main-884d07.o" output.o
clang++.exe: error: linker command failed with exit code 1143 (use -v to
see invocation)

'unordered_map' file not found error when compiling with Xcode 7.3.1

A file in my project fails to compile with
'unordered_map' file not foundIn file included from ...
This is despite I compile with -std=c++ and a directory that has unordered_map in it is in system include paths.
clang -std=c++14 -x c++ -v -E /dev/null
results in the output below. /Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 does contain unordered_map.
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -main-file-name null -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 264.3.102 -v -dwarf-column-info -resource-dir /Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0 -stdlib=libc++ -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /Users/ovz -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ /dev/null
clang -cc1 version 7.3.0 (clang-703.0.31) default target x86_64-apple-darwin15.6.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here: /Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/usr/local/include
/Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/include
/Applications/Xcode_7.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
You need to pass this option:
-stdlib=libc++
to select libc++.
I heard people said that AppleClang uses an old version of libstdc++ (probably from g++) by default. I'm not sure why they made that decision (needless to say, it's understandable in GNU/Linux because most of the time, GNU/Linux is shipped with libstdc++ from g++).

Issue with executing a.out file (C++) MacOS Sierra 10.12.1

I just updated to Sierra and it seems my compiler fell apart for some reason.
The code I wrote worked fine before the update, so I'm sure its not an issue there but now it just isn't working what so ever when I try to execute it.
Here is the output.
$ g++ source.cpp
$ ./a.out
dyld: mach-o, but built for simulator (not macOS)
Abort trap: 6
Running G++ with verbose for #NulledPointer
$ g++ --verbose source.cpp
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin16.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-ios7.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name source.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 274.1 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -stdlib=libc++ -Wno-error -fdeprecated-macro -fdebug-compilation-dir /Users/USERNAME/FILE_DIRECTORY/ -ferror-limit 19 -fmessage-length 130 -stack-protector 1 -fblocks -fobjc-runtime=ios-7.0.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/kr/tvqfrgdx2w32m0c9fq96zddc0000gn/T/source-355902.o -x c++ source.cpp
clang -cc1 version 8.0.0 (clang-800.0.38) default target x86_64-apple-darwin16.1.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/System/Library/Frameworks (framework directory)
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -ios_simulator_version_min 7.0.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -o a.out /var/folders/kr/tvqfrgdx2w32m0c9fq96zddc0000gn/T/source-355902.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/lib/darwin/libclang_rt.ios.a
Error from running that command NulledPointer posted.
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk'
clang: warning: using sysroot for 'MacOSX' but targeting 'iPhone'
In file included from source.cpp:10:
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:215:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:90:10: fatal error:
'wchar.h' file not found
#include <wchar.h> // for mbstate_t
^
1 error generated.
There are multiple options:
Try installing missing tools (if any) using xcode-select --install and try compiling. If that fails,
Try running gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk source.cpp. This obviously assuming you have SDK installed in that location. Replace with whatever location exist there.

Clang on Mac using incorrect C++ version headers

I am attempting to compile a program from the command line on Mac. I already have Xcode and the Xcode command line tools installed.
The problem is that the code in question requires a more current version of the vector class, so it is throwing errors during compilation. After digging into it, I have discovered that the first entry in the default include path is to what looks like a much older version of C++ headers. Searches online indicate this is not normal. So how do I change it?
Here is a command I am running to see the include path:
clang++ -E -x c++ - -v < /dev/null
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 264.3.102 -v -dwarf-column-info -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir / -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ -
clang -cc1 version 7.3.0 (clang-703.0.31) default target x86_64-apple-darwin15.6.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
Notice that the first entry is to .../usr/include/c++/v1
But elsewhere on my system, I have /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1.
The question is, how can I get it to use 4.2.1 headers instead of v1?