Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)
edited by

I made the file hi.cpp and I wrote a command given below:

#include <iostream>

using namespace std;

int main ()

{

  cout << "Hello World! ";

  cout << "I'm a C++ program";

  return 0;

}

then I ran it in the RHEL 6 machine with the below following command

gcc hi.cpp

and I am getting some errors which is as follows:

[chankey@localhost ~]$ gcc hi.cpp

/tmp/cc32bnmR.o: In function `main':

hi.cpp:(.text+0xa): undefined reference to `std::cout'

hi.cpp:(.text+0xf): 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> >&, const char*)'

hi.cpp:(.text+0x19): undefined reference to `std::cout'

hi.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> >&, const char*)'

/tmp/cc32bnmR.o: In function `__static_initialization_and_destruction_0(int, int)':

hi.cpp:(.text+0x4c): undefined reference to `std::ios_base::Init::Init()'

hi.cpp:(.text+0x51): undefined reference to `std::ios_base::Init::~Init()'

/tmp/cc32bnmR.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'

collect2: ld returned 1 exit status

[chankey@localhost ~]$ 

What do the errors denote? when my code is correct why am I getting errors?

1 Answer

0 votes
by (36.8k points)

Use the g++

g++ -o hi hi.cpp

g++ is for C++, gcc is for the C although with a -libstdc++ you can compile c++ most people don't do this.

Come and join Linux training to gain great knowledge. 

Do check out the video below

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 28, 2020 in Linux by blackindya (18.4k points)
0 votes
1 answer
asked Nov 29, 2020 in Linux by blackindya (18.4k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...