0

[This problem is showing when i am trying to compile my code in vs code]

enter image description here

I tried to solve this problem by editing json file but nothing works.

This is I am getting after compilation:

Executing task: C/C++: gcc.exe build active file

Starting build... cmd /c chcp 65001>nul && C:\MinGW\bin\gcc.exe -fdiagnostics-color=always -g "C:\Users\akanksha yadav\Desktop\cppcodes\helloworld.cpp" -o "C:\Users\akanksha yadav\Desktop\cppcodes\helloworld.exe" C:\Users\AKANKS~1\AppData\Local\Temp\ccW7k8xx.o: In function main': C:/Users/akanksha yadav/Desktop/cppcodes/helloworld.cpp:5: undefined reference to std::cout' C:/Users/akanksha yadav/Desktop/cppcodes/helloworld.cpp:5: 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:\Users\AKANKS~1\AppData\Local\Temp\ccW7k8xx.o: In function _tcf_0': c:/mingw/lib/gcc/mingw32/6.3.0/include/c++/iostream:74: undefined reference to std::ios_base::Init::~Init()' C:\Users\AKANKS~1\AppData\Local\Temp\ccW7k8xx.o: In function _static_initialization_and_destruction_0': c:/mingw/lib/gcc/mingw32/6.3.0/include/c++/iostream:74: undefined reference to `std::ios_base::Init::Init()' collect2.exe: error: ld returned 1 exit status

Build finished with error(s).

  • The terminal process terminated with exit code: -1.
  • Terminal will be reused by tasks, press any key to close it.
0

1 Answer 1

0

Executing task: C/C++: gcc.exe build active file

the above is the problem. you are compiling c++ file with straight c compiler

for compiling .cpp files we use g++.exe

that's why the logs are screaming at you with errors such as undefined reference to std::cout . std::cout does not exist in .c files

Solution

  1. edit your build configurations on your VSc*de so that it uses g++.exe instead of gcc.exe OR
  2. Raw-dog it by typing g++ helloworld.cpp -o helloworld.exe && .\helloworld.exe on VSc*de terminal.

welcome to the world of hair-yanking! :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.