Reputation: 353
okay this I did accidentally , compiling .cpp using gcc and not g++
but I actually want to understand the console output, line by line, if it has any sense.
struct a{
int pointer;
int rollno;
};
struct a student,*studentref;
studentref = &student;
studentref->rollno = 141;
studentref->pointer = 8;
cout<<studentref->rollno<<") : "<<studentref->pointer<<endl;
compiling this code with gcc structpointers.cpp -o structp
gives the following output:
sourab@sourab:/home/gbear/coding/learningds$ gcc structpointers.cpp -o structp
/tmp/ccXrq1Cv.o: In function `main':
structpointers.cpp:(.text+0x2e): undefined reference to `std::cout'
structpointers.cpp:(.text+0x33): undefined reference to `std::ostream::operator<<(int)'
structpointers.cpp:(.text+0x38): 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> >&)'
structpointers.cpp:(.text+0x40): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/ccXrq1Cv.o: In function `__static_initialization_and_destruction_0(int, int)':
structpointers.cpp:(.text+0x6e): undefined reference to `std::ios_base::Init::Init()'
structpointers.cpp:(.text+0x7d): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
Upvotes: 1
Views: 706
Reputation: 667
g++ and gcc are compiler drivers of GNU compiler collection, they have backends which are connected automatically once compilation mode in up. The errors like "
structpointers.cpp:(.text+0x2e): undefined reference to `std::cout'
are link errors,since you have used gcc to compile cpp,the standard libraries specifically for cpp are not present, so it could not find syntax like std::cout etc.
you can also refer to : compiling with g++
Upvotes: 0
Reputation: 126777
The most egregious difference between calling g++
and gcc
on a .cpp
file is that g++
automatically links in the C++ standard library, while gcc
does not; all the errors you see are linker errors of missing references to stuff that is provided by the C++ standard library.
(notice that this isn't the only difference; see this question for details)
Upvotes: 2