基本上当我点击运行时会出现错误
[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/