我正在使用 VS Code 版本 1.62.0(用戶設定)
我正在嘗試用 C (test.c) 運行一個基本程式:
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Hello");
return 0;
}
我試圖通過單擊播放標志 (CTRL ALT N) 來運行,但它在終端中變成這樣:
PS C:\Users\X\Dropbox\My PC_X\Downloads> cd "c:\Users\X\Dropbox\My PC_X\Downloads\est\" ; if ($?) { g test.c *.c -o test } ; if ($?) { .\test }
C:\Users\X\AppData\Local\Temp\ccyBS6yO.o:test.c:(.text 0x0): multiple definition of `main'
C:\Users\X\AppData\Local\Temp\ccwvYj0K.o:test.c:(.text 0x0): first defined here
collect2.exe: error: ld returned 1 exit status
我不知道這些資訊是否有幫助。供您參考,我使用的是 Windows 11(在我的情況下,我認為它真的壞了)。以前,我將 [桌面、檔案、圖片] 與 OneDrive 同步(OneDrive 成為我的本地檔案夾)。但是兩天前,我關閉了 Documents 的同步,有些檔案完全在 OneDrive 中(不一定在我的本地檔案夾中)[為了更清楚,請看圖片]

這是我的 gcc 版本:
gcc.exe (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
這是我的 task.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C : gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: C:\\MinGW\\bin\\gcc.exe"
}
]
}
uj5u.com熱心網友回復:
if ($?) { g test.c *.c -o test }
啊,等*.c你擴容后跑
g test.c test.c -o test
因此,正如錯誤訊息所說,您已經main定義了兩次 - 在test.c. 因此,*.c從您的構建作業中洗掉。
uj5u.com熱心網友回復:
來自您的 IDE 配置,您正在嘗試編譯您的檔案,然后編譯所有 .c 檔案,因此包含第一個檔案,因此它有 2 個 main,因為您編譯了兩次相同的檔案
g test.c *.c -o test
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/353299.html
