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

标签 c++ visual-studio-code compiler-errors g++ syntax-error

基本上当我点击运行时会出现错误

[Running] cd "c:\Users\alexv\Documents\Playground\" && g++ Hello_World -o c:\Users\alexv\Documents\Playground\Hello_World && "c:\Users\alexv\Documents\Playground\"c:\Users\alexv\Documents\Playground\Hello_World c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe:Hello_World: file format not recognized; treating as linker script c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe:Hello_World:1: syntax error collect2.exe: error: ld returned 1 exit status

我正在使用 VSC、MinGW 和一台 PC,我尝试运行的程序是一个简单的 hello world:

#include <iostream>

using namespace std;

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

    return 0;
}

最佳答案

如评论中所述,错误信息比较清楚。

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

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

为 C++ 源文件使用一种常见的文件扩展名,g++ 将正确处理该文件,无需其他选项。常见的 C++ 源文件扩展名为 .cpp.cc.cxx

关于c++ - 这是我第一次编程,我无法运行我的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59362793/

相关文章:

macos - 在Visual Studio Code中仅缩放文本

compiler-errors - 已添加具有相同 key 的项目 .Net 原生工具链

c++ - 错误 : expected primary-expression before 'long' and invalid conversion

c++ - boost::可选,带有 const 成员

c++ - 是否可以在邻接列表中删除我的 Boost Graph 中的顶点?

c++ - Chromium源代码编译

c++ - 检查一个元素是否存在于二维数组中,如果为真则返回

ubuntu - .Net 核心 sdk 在 ubuntu 18.10

perl - VSCode 扩展 : code-outline for Perl . cgi 文件

c - 我该如何解决这个错误? (未定义对 'display_menu' 的引用)