edit: My question is not related to Link errors using <filesystem> members in C++17 at all! -lstdc++fs is not available on clang14 for macOS 10.13
edit2: Latest Xcode for macOS 10.13 is clang10, that is another reason for using clang14 from llvm. Also I can not update Xcode because my macOS Is stuck at high-serria
I am compiling the minimal example below with clang14.
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
std::cout << "Current path is " << fs::current_path() << '\n';
}
as follows:
clang-14++ path.cpp -std=c++20
which results in a linking error:
ld64.lld: error: undefined symbol: std::__1::__fs::filesystem::__current_path(std::__1::error_code*)
>>> referenced by /var/folders/_z/1q84ymcj36dgx7d2z7ybs6h40000gn/T/path-201e1b.o
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
running -v outputs the following: https://pastebin.com/G1PDDkTJ
My understanding is that -lc++ is linking against the system's default libc++ (the one shipped with apple-clang and not the one with shipped clang14)
I verified that by appending -L/path/to/clang14/lib/folder before the -lc++ and it did compile and work however, generated the warning:
ld64.lld: warning: /Users/alia/.local/clang_llvm_apple/lib/libc++.dylib has version 11.6.0, which is newer than target minimum of 10.13.0
ld64.lld: warning: /Users/alia/.local/clang_llvm_apple/lib/libunwind.dylib has version 11.6.0, which is newer than target minimum of 10.13.0
any way to tell clang to link against its own default libc++? or should I just alias some command to compile first and then append -L as above and link? also, does this have any impact or possible gotchas that I should be aware of? I am using clang14 because apple-clang doesn't support address sanitizers.