这是我第一次编程,我无法运行我的代码

问题描述 投票:1回答:1

基本上是单击运行错误时出现的错误

[正在运行] cd“ c:\ Users \ alexv \ Documents \ Playground \” && g ++ Hello_World -oc:\ Users \ alexv \ Documents \ Playground \ Hello_World &&“ c:\ Users \ alexv \ Documents \ Playground \” c :\ Users \ alexv \ Documents \ Playground \ Hello_Worldc:/ mingw / bin /../ lib / gcc / mingw32 / 6.3.0 /../../../../ mingw32 / bin / ld.exe:Hello_World:无法识别文件格式;视为链接描述文件c:/ mingw / bin /../ lib / gcc / mingw32 / 6.3.0 /../../../../ mingw32 / bin / ld.exe:Hello_World:1:语法错误collect2.exe:错误:ld返回1退出状态

我正在使用VSC,MinGW和PC,我尝试运行的程序是一个简单的世界:

#include <iostream>

using namespace std;

int main() {
    cout << "Hello world" << endl;

    return 0;
}
c++ visual-studio-code compiler-errors g++ syntax-error
1个回答
2
投票

如评论中所述,错误消息相对清晰。

g++接受几种不同类型的文件作为参数。它通过查看文件扩展名来尝试确定您要处理的文件类型。

您的文件没有扩展名,因此g++默认假定它是一个链接描述文件,但实际上它是C ++源文件。

使用C ++源文件的通用文件扩展名之一,并且g++将正确处理该文件,而无需其他选择。常见的C ++源文件扩展名是.cpp.cc.cxx

© www.soinside.com 2019 - 2024. All rights reserved.