简体   繁体   English

C++ 文件停止编译 - 不断出现错误:linker 命令失败,退出代码为 1(使用 -v 查看调用)

[英]C++ files stopped compiling - keep getting error: linker command failed with exit code 1 (use -v to see invocation)

I've had no problems compiling in the past, and code that I wrote previously is compiling fine, but it is now giving this error when I try to compile a very simple C++ file using Visual Studio Code on my M1 Mac:我过去编译没有问题,我之前编写的代码编译良好,但现在当我尝试在我的 M1 Mac 上使用 Visual Studio Code 编译一个非常简单的 C++ 文件时出现此错误:

Code:代码:

#include<iostream>
using namespace std;

int main() {
    cout << "Hello World" << endl;
    return 0;
}

The terminal commands I've tried (all give same error):我尝试过的终端命令(都给出相同的错误):

g++ -std=c++14 test.cpp -o test
g++ -std=c++11 test.cpp -o test
g++ test.cpp -o test

Error:错误:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've tried to delete and re-create the file with different names, restarting VSC, using different output file names and nothing changes this.我尝试删除并重新创建具有不同名称的文件,重新启动 VSC,使用不同的 output 文件名,但没有任何改变。

This was occurring as I hadn't saved the file prior to compiling and therefore the compiler couldn't find it.发生这种情况是因为我在编译之前没有保存文件,因此编译器找不到它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 编译我的 C++ 程序:clang: error: linker command failed with exit code 1(使用 -v 查看调用) - Compiling my c++ program: clang: error: linker command failed with exit code 1 (use -v to see invocation) 获取错误clang:错误:从终端编译C ++文件时,链接器命令失败,退出代码为1(使用-v查看调用) - Getting error clang: error: linker command failed with exit code 1 (use -v to see invocation) while compile C++ file from terminal XCode C++ 链接器命令失败,退出代码为 1(使用 -v 查看调用) - XCode C++ linker command failed with exit code 1 (use -v to see invocation) Mac上的C ++:链接器命令失败,退出代码为1(使用-v查看调用) - C++ on mac : linker command failed with exit code 1 (use -v to see invocation) Xcode:链接器命令失败,退出代码为1(使用-v查看调用)[C ++] - Xcode: linker command failed with exit code 1 (use -v to see invocation) [C++] 链接器命令在 macos 上失败,退出代码为 1(使用 -v 查看调用) - linker command failed with exit code 1 (use -v to see invocation) on macos Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用) - Xcode linker error: linker command failed with exit code 1 (use -v to see invocation) C ++编译错误:ld:找不到架构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看调用) - C++ compilation error: ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Netbeans 10:错误:链接器命令失败,退出代码为1(使用-v查看调用) - Netbeans 10: error: linker command failed with exit code 1 (use -v to see invocation) clang:错误:在cmake中链接库时,链接器命令失败,退出代码为1(使用-v查看调用) - clang: error: linker command failed with exit code 1 (use -v to see invocation) when linking library in cmake
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM