-1

im making first cpp program (using windows gcc compiler) but i got that error:

c:/users/oops9_wimj8q/scoop/apps/gcc/current/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\OOPS9_~1\AppData\Local\Temp\ccL9PsTD.o:main.cpp:(.text+0x22): 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/oops9_wimj8q/scoop/apps/gcc/current/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\OOPS9_~1\AppData\Local\Temp\ccL9PsTD.o:main.cpp:(.text+0x34): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
c:/users/oops9_wimj8q/scoop/apps/gcc/current/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\OOPS9_~1\AppData\Local\Temp\ccL9PsTD.o:main.cpp:(.text+0x56): undefined reference to `std::ios_base::Init::~Init()'
c:/users/oops9_wimj8q/scoop/apps/gcc/current/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\OOPS9_~1\AppData\Local\Temp\ccL9PsTD.o:main.cpp:(.text+0x89): undefined reference to `std::ios_base::Init::Init()'
c:/users/oops9_wimj8q/scoop/apps/gcc/current/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\OOPS9_~1\AppData\Local\Temp\ccL9PsTD.o:main.cpp:(.rdata$.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_[.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_]+0x0): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
c:/users/oops9_wimj8q/scoop/apps/gcc/current/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\OOPS9_~1\AppData\Local\Temp\ccL9PsTD.o:main.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): undefined reference to `std::cout'
collect2.exe: error: ld returned 1 exit status
#include <iostream>
using namespace std;

int main() {

    cout << "Hello, World!" << endl;
    return 0;
    
}

i dont know what i should try

BadDream89
  • 11
  • 2
  • 4
    `gcc` is a C compiler, call `g++` for C++. Also, the most important error is the first one, not the last one. – HolyBlackCat Aug 19 '23 at 09:53
  • If you search for `collect2.exe: error: ld returned 1 exit status` you would get several thousands of hits. If you then add the terms `gcc` and `c++` you would quite easily have found the answer to your problem. – Some programmer dude Aug 19 '23 at 10:04
  • [Exact duplicate](https://stackoverflow.com/a/67236678/775806) – n. m. could be an AI Aug 19 '23 at 10:22
  • Does this answer your question? [Compiling a C++ program with GCC](https://stackoverflow.com/questions/3178342/compiling-a-c-program-with-gcc) – machine_1 Aug 19 '23 at 10:59

1 Answers1

0

If you use gcc for C++ code, you have to manually link against the C++ standard library. g++, the c++ compiler however, automatically links against the C++ standard library, so change:

gcc main.cpp -o myProgram

to

g++ main.cpp -o myProgram
machine_1
  • 4,266
  • 2
  • 21
  • 42