Mac VSCode报错:ld: can't open output file for writing: test, errno=21 for architecture x86_64

写了一个用于测试的C++文件,运行时一直报错

[Running] cd "/Users/fenglunli/Desktop/" && g++ test.cpp -o test && "/Users/fenglunli/Desktop/"test
ld: can't open output file for writing: test, errno=21 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

以为VSCode出问题了,于是转战Eclipse,然而依旧报错。

于是把代码精简成了这样:

#include
using namespace std;
int main(){
int i= 0;
cout<
}

依然报错。


于是求助万能的百度。


嗯是Mac的问题。


于是我把test.cpp的文件名改为test-1.cpp

[Running] cd "/Users/fenglunli/Desktop/" && g++ test-1.cpp -o test-1 && "/Users/fenglunli/Desktop/"test-1
0

[Done] exited with code=0 in 0.412 seconds


成功!

嗯因为桌面上还有一个test.c文件

编译时mac下相同目录如果有同名文件那就会一直报错。


你可能感兴趣的:(Mac VSCode报错:ld: can't open output file for writing: test, errno=21 for architecture x86_64)