/Library/WebServer/CGI-Executables
❯ clang++ ./sort.cpp -o sort -std=c++11
ld: can't open output file for writing: sort, errno=13 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
/Library/WebServer/CGI-Executables
❯ sudo clang++ ./sort.cpp -o sort -std=c++11
(此处编译成功)
/Library/WebServer/CGI-Executables
❯ sudo bash
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit
https://support.apple.com/kb/HT208050.
bash-3.2# ls
sort sort.cpp
bash-3.2# clang++ ./sort.cpp -std=c++11
bash-3.2#
我认为你这个问题不能复现的概率接近 100%,sudo 不保留环境变量,这个目录单纯是因为没有权限才导致的无法编译,和环境变量没有关系