Compiling error help please

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2008
Posts: 31
Reputation: JustLearning is an unknown quantity at this point 
Solved Threads: 0
JustLearning JustLearning is offline Offline
Light Poster

Compiling error help please

 
0
  #1
Feb 28th, 2009
Ok here is the code I am trying to compile remotly on a linux machine
I am getting quite a few compile errors when I try to compile this
Here is just a sample of the errors I am getting.
  1. -bash-3.2$ gcc -o lemastsGCD lemastsGCD.cpp
  2. /tmp/cca8g62Q.o: In function `__static_initialization_and_destruction_0(int, int)':
  3. lemastsGCD.cpp:(.text+0x51): undefined reference to `std::ios_base::Init::Init()'
  4. /tmp/cca8g62Q.o: In function `__tcf_0':
  5. lemastsGCD.cpp:(.text+0x9a): undefined reference to `std::ios_base::Init::~Init()'
  6. /tmp/cca8g62Q.o: In function `gcdr(int, int)':
  7. lemastsGCD.cpp:(.text+0xb1): undefined reference to `std::cout'
  8. lemastsGCD.cpp:(.text+0xb6): 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. lemastsGCD.cpp:(.text+0xc7): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
  10. lemastsGCD.cpp:(.text+0xd7): 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*)'
  11. lemastsGCD.cpp:(.text+0xe8): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
  12. lemastsGCD.cpp:(.text+0xf8): 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*)'
  13. lemastsGCD.cpp:(.text+0x100): 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> >&)'
  14. lemastsGCD.cpp:(.text+0x108): 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> >&))'
  15. /tmp/cca8g62Q.o: In function `main':
  16. lemastsGCD.cpp:(.text+0x166): undefined reference to `std::cout'
  17.  

Now on my home machine I have no problem compiling this I am using Dev C++ at home on a windows machine.

What Am I doing wrong
  1. #include <iostream>
  2.  
  3. int gcdr(int a, int b); // recursive function declaration
  4.  
  5. int gcdi(int a, int b); // iterative function declaration
  6.  
  7. using namespace std;
  8.  
  9. int main(int argc, char *argv[]) // Command line arguments
  10. {
  11.  
  12. if (argc != 4) // If the command line does not receive four
  13. // arguments if statement is entered
  14. {
  15. cout << "\nProgram usage: program name.exe type of algorithm -r or -i integer integer\n";
  16. // Statement to user that an error has occur ed
  17. return -1; // Terminate program
  18. }
  19. int x,y,swap; // Variables to hold input integers from user
  20. string GCDtype; // String variable to hold the type of function
  21. // to be used.
  22.  
  23. GCDtype = argv[1]; // Variable to save the type of function to be run
  24. swap = 0; // Integer variable used for swap
  25. x = atoi(argv[2]); // Varable to hold first integer input
  26. y = atoi(argv[3]); // Viable to hold second integer input
  27.  
  28. if (x <= y) // If statement to swap integers in the case
  29. // that the first integer is larger than second
  30. {
  31. swap = x; // set swap variable equal to x
  32. x = y; // set x equal to y
  33. y = swap; // set y equal to swap variable
  34. }
  35.  
  36. if (GCDtype == "-r") // If statement for recursive function
  37. {
  38. cout << "\nStarting recursion" << endl; // Inform user starting recursion
  39. // start of recursion
  40. cout << "gcd by recursive algorithm is " << gcdr(x, y)/* function call*/ << endl;
  41. }
  42. else if (GCDtype == "-i") // Else if for iterative function
  43. {
  44. // Run GCDi function
  45. cout << "\ngcd by iterative algorithm is " << gcdi(x,y)/* function call*/ << endl;
  46. }
  47. else // Inform user that -r or -i was not entered
  48. {
  49. cout << "\nIncorrect use of program. Correct use is as follows\n";
  50. cout << "Program Name.exe -r or -i integer integer" << endl;
  51. }
  52. return -1; // End program
  53. }
  54.  
  55. int gcdr(int a, int b) // Function recursive
  56. {
  57. cout << "Finding gcd(" << a << "," << b << ")" << endl;
  58. return ( b == 0 ? a : gcdr(b, a % b) ); // Run recursion until GCD is found
  59. }
  60.  
  61. int gcdi(int a, int b) // Function iterative
  62. {
  63. int c; // Variable to hold b
  64.  
  65. while (b != 0) // Run while b does not equal zero
  66. {
  67. c = b;
  68. b = a % b; // b now equals a mod b
  69. a = c; // a now equals what b was
  70. }
  71. return a;
  72. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Compiling error help please

 
0
  #2
Feb 28th, 2009
Try g++ (c++ compiler) instead of gcc (c compiler).
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 31
Reputation: JustLearning is an unknown quantity at this point 
Solved Threads: 0
JustLearning JustLearning is offline Offline
Light Poster

Re: Compiling error help please

 
0
  #3
Feb 28th, 2009
Exactly right thank you.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC