簡體   English   中英

為什么這個 hello world 程序無法鏈接?

[英]Why is this hello world program failing to link?

#include <stdio.h>
int main() {
   printf("Hello, World!");
   return 0;
}

我在 Mac Silicon 上安裝了 VScode 和 gcc,嘗試在 C 中運行上述 hello world 程序,但出現以下錯誤:

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

當我在終端上運行以下命令時,我得到了這個:

which gcc
/usr/bin/gcc

which gcc-11
/opt/homebrew/bin/gcc-11

我不確定我是否錯誤地安裝了編譯器(第一次嘗試 C)。

剛開始時,我建議您在tasks.json (終端 -> 配置任務)中執行類似這樣的簡單任務:

{
  "tasks": [
    {
      "label": "Run my C",
      "type": "shell",
      "command": "gcc -o myoutput ${file} && ./myoutput",
      "group": {
           "kind": "build",
           "isDefault": true
       },

      }
    }
  ],
"version": "2.0.0"
}

這將編譯它並立即運行./myoutput (在 vscode 的終端內)。 isDefault表示它是默認構建任務,因此您可以通過 Ctrl+Shift+B 運行它(也在終端 -> 運行構建任務下)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM