c++ - 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:
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.
解决方案
发生这种情况是因为我在编译之前没有保存文件,因此编译器找不到它。
推荐阅读
- python - LinkedIn V2 API Marketing Developer Platform - 获取 ugcPost 参考 URN 的数据返回 500 错误
- postgresql - 现有数据集上的 Postgres 13 + pglogical 2.3.4
- python - plt.hist MatPlotlib 中的 bins 选项
- i2c - 读取 I2C 传感器时 Pi Pico 错误 EIO
- python - 合并 txt 文件问题,输出文件不是 txt
- python - 如何绘制 pytorch 张量?
- c - 通过文件描述符或套接字轮询 X 事件
- structure - 为什么 STRUCTURE v2.3.4(命令行)不起作用?
- typescript - 为什么在 strictNullChecks 开启时 null 变量仍会扩大以键入任何内容?
- tableau-desktop - 在 Tableau 中使用布尔值和 LOD