LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 12-10-2004, 08:23 PM   #1
CooManChu
Member
 
Registered: Dec 2004
Location: Chicago, IL
Distribution: Ubuntu 10
Posts: 46

Rep: Reputation: 15
Question 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
 
Old 12-11-2004, 10:20 AM   #2
CooManChu
Member
 
Registered: Dec 2004
Location: Chicago, IL
Distribution: Ubuntu 10
Posts: 46

Original Poster
Rep: Reputation: 15
Lightbulb

Never mind...

After looking at this a little more, I think the main difference is what gcc passes to the assembly/linkage steps compared to what g++ passes to these steps.

Running each compiler from the command line in verbose mode showed the following.

g++ by default was passing link parms: -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
gcc by default was passing link parms: -lgcc -lgcc_eh -lc -lgcc -lgcc_eh

Simply adding -lstdc++ to the parm list when invoking gcc (gcc -lstdc++ hello.cpp) results in the expected a.out. Hopefully, I'll run into a more intersting/challenging problem to post in the future. : )

Scott
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
iostream not found krsnachaitanya Linux - Software 4 02-10-2005 07:47 AM
/lib/libpthread.so.): version 'GLIBC_2.3.2' not found solutionseeker Linux - Newbie 21 01-29-2005 10:02 PM
/usr/lib/libstdc++.so.5: version 'GLIBCPP_3.2.2' not found vidi Linux - Software 1 06-10-2004 10:26 AM
xauth: /lib/i686/libc.so.6: version 'GLIBC_2.3.2' not found yigald Linux - Newbie 0 02-21-2004 12:52 AM
/lib/ld-linux.so.2: version 'GLIBC_PRIVATE' not found error nienamusa Red Hat 0 02-04-2004 10:16 PM


All times are GMT -5. The time now is 09:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration