The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help:NFS mknod failed steeles SUN Solaris 0 01-25-2008 08:05 AM
Failed to power up fredginting SUN Solaris 2 01-07-2008 07:05 PM
Backup failed nervous UNIX for Dummies Questions & Answers 10 01-02-2008 11:50 PM
Last Failed Login gilberteu SUN Solaris 2 08-06-2007 07:32 PM
dlopen failed! virmin High Level Programming 1 10-30-2005 08:19 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-08-2006
Registered User
 

Join Date: Apr 2006
Posts: 28
g++ is OK while gcc is failed

[test.cpp]

#include <iostream>
using namespace std;

int main(void)
{
cout << "hello" << endl;
return 0;
}

I tried this:
1) g++ test.cpp -o test // It's OK

2) gcc test.cpp -o test // Failed

/tmp/ccriZviL.o(.text+0x14): In function `main':
: 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> >&)'
/tmp/ccriZviL.o(.text+0x21): In function `main':
: undefined reference to `std::cout'
/tmp/ccriZviL.o(.text+0x26): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccriZviL.o(.text+0x2f): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccriZviL.o(.text+0x5c): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccriZviL.o(.text+0x8b): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccriZviL.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status


In my case, I am only allowed to use gcc.
How to use gcc to let the compilation & link pass? Any comiple/link arguments needed?

Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-08-2006
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 356
libstdc++ hasn't been linked, so

$ gcc test.cpp -lstdc++ -o test
Reply With Quote
  #3 (permalink)  
Old 07-08-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,868
Why is it that you can only use gcc? Sounds like homework....
Reply With Quote
  #4 (permalink)  
Old 07-08-2006
Registered User
 

Join Date: Apr 2006
Posts: 28
Thank you, Hitori.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0