gcc vs. g++ -> iostream lib found vs. not found
Hi,
I'm using C++ on my Linux machine (Redhat 9.0) and I have a question. I was wondering if someone could tell me the main differences between using gcc and g++ as my compiler. The reason I'm curious about the differences is because when I issue gcc from the command line, the link step fails due to unresolved library references.
As a test program, I coded up the standard "Hello world" program in C++:
#include <iostream>
int main()
{
std::cout << "Hello world.\n";
return 0;
}
Issuing gcc hello.cpp results in link errors. Mainly:
undefined reference to `std::cout'
Running gcc in verbose mode (gcc -v hello.cpp) shows the include lib search order:
#include <...> search starts here:
/usr/include/c++/3.2.2
/usr/include/c++/3.2.2/i386-redhat-linux
/usr/include/c++/3.2.2/backward
/usr/local/include
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/include
/usr/include
End of search list.
I definately can find iostream in /usr/include/c++/3.2.2., but it looks as if the lib is not being pulled in for the link.
Issuing g++ hello.cpp compiles and links everything just fine. The resulting a.out executable runs as expected.
Could someone explain what it is that I need to do to use gcc correctly in this case or if I really need to bother since I can use g++ (is there a preference for gcc over g++ in any cases)?
Thanks alot,
Scott Cook
Chicago, IL
|