473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why is my gcc behaving strangely?

AmberJain
884 Expert 512MB
Hello,

This is a simple C++ code (which is there in C++ primer):

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. std :: cout << "Enter the numbers: " << std :: endl;
  6. int v1, v2;
  7.  
  8. std :: cin >> v1 >> v2;
  9. std :: cout << "The sum of " << v1 << " and " << v2<< " is " << v1 + v2 << std :: endl;
  10.  
  11. return 0;
  12. }
Now when I try compiling with gcc 3.3.5 under OpenBSD 4.4, I get following output at terminal:

Expand|Select|Wrap|Line Numbers
  1. $gcc -o file file.cpp
  2. try.cpp:13:2: warning: no newline at end of file
  3. /tmp//ccF18167.o(.text+0x1c): In function `main':
  4. : 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> >&)'
  5. /tmp//ccF18167.o(.text+0x29): In function `main':
  6. : undefined reference to `std::cout'
  7. /tmp//ccF18167.o(.text+0x2e): In function `main':
  8. : 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> >&, char const*)'
  9. /tmp//ccF18167.o(.text+0x37): In function `main':
  10. : undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
  11. /tmp//ccF18167.o(.text+0x4d): In function `main':
  12. : undefined reference to `std::cin'
  13. /tmp//ccF18167.o(.text+0x52): In function `main':
  14. : undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
  15. /tmp//ccF18167.o(.text+0x5b): In function `main':
  16. : undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
  17. /tmp//ccF18167.o(.text+0x66): In function `main':
  18. : 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> >&)'
  19. /tmp//ccF18167.o(.text+0x99): In function `main':
  20. : undefined reference to `std::cout'
  21. /tmp//ccF18167.o(.text+0x9e): In function `main':
  22. : 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> >&, char const*)'
  23. /tmp//ccF18167.o(.text+0xa7): In function `main':
  24. : undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
  25. /tmp//ccF18167.o(.text+0xb0): In function `main':
  26. : 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> >&, char const*)'
  27. /tmp//ccF18167.o(.text+0xb9): In function `main':
  28. : undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
  29. /tmp//ccF18167.o(.text+0xc2): In function `main':
  30. : 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> >&, char const*)'
  31. /tmp//ccF18167.o(.text+0xcb): In function `main':
  32. : undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
  33. /tmp//ccF18167.o(.text+0xd4): In function `main':
  34. : undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
  35. /tmp//ccF18167.o(.text+0x11e): In function `__static_initialization_and_destruction_0(int, int)':
  36. : undefined reference to `std::ios_base::Init::Init()'
  37. /tmp//ccF18167.o(.text+0x14d): In function `__tcf_0':
  38. : undefined reference to `std::ios_base::Init::~Init()'
  39. /tmp//ccF18167.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
  40. collect2: ld returned 1 exit status
  41.  
Now I dont know the reason for this. I even tried using gcc under linux, MinGW under windows but got similar compiler output.
If I try compiling with g++, all is fine. But as man page says, gcc and g++ are same. So what is the problem?

Thanks.....
AmbrNewlearner
Nov 21 '08 #1
1 2355
r035198x
13,262 8TB
gcc and g++ are not the same. g++ is for compiling c++ files while gcc is for c files. gcc will compile as c++ when it sees a file extension it regards to be c++ but it will not link the object files created during the compilation correctly itself, which is why you are getting those errors.
Nov 21 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Drew Lettington | last post by:
I'm making a simple call to display error messages in a MessageBox from a Windows form and the MessageBox is not behaving in a modal fashion. My modal form displays, the user clicks a button and...
5
by: amit kumar | last post by:
I am calling a function which returns pointer to a map. The declaration of the map is map<int,vectxyz*>. vectxyz is a vector containing pointer to a class xyz. For map<int,vectxyz*>* p1 In the...
8
by: DamonChong | last post by:
Hi, I am new and had this piece of code which I created but it is not behaving as expected. I'm using g++, can someone help me out? Thank you. //--------file (Object.cc)----------- class Object...
10
by: ellre923 | last post by:
I use gdb to trace the following code and find "howlong" is changed strangely. int CmDispatch::waitFor(timeval* howlong) { int nfound=-1; for(;nfound<0;) { CmFdSet& r=onRead_->onSelects();...
0
by: elime | last post by:
Hi all I have a strange behaving on some PC with my DataGrid. It only occurs on some PC, on others it works perfectly fine. ->(same ..net version installed) it's very confusing. starting...
3
by: Steve - DND | last post by:
I just implemented a page that performs a Response.Redirect(url, true). As such, I wrapped it in a try catch, and explicitly caught a ThreadAbortException. However, the thread abort exception was...
2
by: bingomanatee | last post by:
I have developed what amounts to a fancy shopping cart wizard for a scientific instrument using VB.NET. We are having some disturbing phenomena relating to dropdown controls. On my system and...
2
by: sujitksharma | last post by:
Hi, Following is a simple html which has a table with one "<tr>" and two "<td>". Both the "<td>"s have a fixed width of "150px". In one "<td>" I have put some long text, while in the second "<td>"...
0
by: bill.wu | last post by:
the tutor list has been strangely silent for a few days. Anyone know what has happened? why?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.