【问题标题】:MacOS VS Code C++ error: Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executableMacOS VS Code C++ 错误:体系结构 x86_64 的未定义符号:\"_main\",引用自:主可执行文件的隐式入口/启动
【发布时间】:2022-12-12 08:51:55
【问题描述】:

在 visual studio code 上,在 2020 I7 Mac 上,在任何 c++ 程序(这是我检查过的唯一一个公平的程序)上,我收到此错误:

[Running] cd "/Users/creaturesceptique/projects/helloworld/" && g++ Wontwork.cpp -o 

Wontwork && "/Users/creaturesceptique/projects/helloworld/"Wontwork
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)

[Done] exited with code=1 in 0.1 seconds

我的 C++ 代码是:

#include <iostream>
using namespace std;

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

我对此很陌生,所以请容忍我的愚蠢......

顺便说一句,我正在使用基本的 Code Runner 和 Microsoft c/c++ 扩展。

【问题讨论】:

  • 代码看起来不错,很可能是 VS Code [缺乏] 配置。你是如何安装你的编译器的?
  • C++ 不是脚本语言。
  • 似乎 VS Code 默认设置是不是在编译之前将文件保存到磁盘。

标签: c++ macos compiler-errors


【解决方案1】:

我遇到了同样的问题,只要你在 VS 代码中运行了所有正确的扩展,并且在终端中安装了命令行开发人员工具,你应该没问题。有时 VS Code 很笨,所以只需退出程序或重新启动 mac。

【讨论】:

    猜你喜欢
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 2014-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多