我正在尝试用c++高级文本编译。我已经设法在我的计算机上安装了MinGw的相关软件包。以及在C:\MinGW\bin目录下的系统环境变量中创建一个路径文件,它的确切位置。并随后在编辑器中生成了一个新的构建系统,包括:
{
"cmd" : "gcc $file_name -o ${file_base_name} && ${file_base_name}",
"selector" : "source.c",
"shell": true,
"working_dir" : "$file_path"
}我进一步检查了cmd是否正确地安装了编译器,而且它是正确的。
>gcc --version
gcc (MinGW.org GCC Build-2) 9.2.0
Copyright (C) 2019 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.我输入了崇高的代码:
#include<iostream>
using namespace std;
int main(){
cout<<"hello world";
}汇编的结果如下:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\44750\AppData\Local\Temp\ccVYP6T2.o:item.cpp:(.text+0x19): undefined reference to `std::cout'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\44750\AppData\Local\Temp\ccVYP6T2.o:item.cpp:(.text+0x1e): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\44750\AppData\Local\Temp\ccVYP6T2.o:item.cpp:(.text+0x35): undefined reference to `std::ios_base::Init::~Init()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\44750\AppData\Local\Temp\ccVYP6T2.o:item.cpp:(.text+0x56): undefined reference to `std::ios_base::Init::Init()'
collect2.exe: error: ld returned 1 exit status
[Finished in 0.8s]发布于 2020-08-23 14:22:45
您将gcc设置为编译器,但您正在构建c++。
使用gcc进行构建可能允许它编译C++,但它不会自动链接到所需的标准库中--这会导致您正在经历的链接错误失败。
要么将cmd更改为使用g++,要么添加标志"-x c++“,以便它知道这是C++代码,这将允许它提取正确的库。
https://stackoverflow.com/questions/63548024
复制相似问题