943,515 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 909
  • C++ RSS
Feb 28th, 2009
0

Compiling error help please

Expand Post »
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.
C++ Syntax (Toggle Plain Text)
  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
c++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
JustLearning is offline Offline
31 posts
since Sep 2008
Feb 28th, 2009
0

Re: Compiling error help please

Try g++ (c++ compiler) instead of gcc (c compiler).
Reputation Points: 163
Solved Threads: 91
Posting Pro in Training
nucleon is offline Offline
476 posts
since Oct 2008
Feb 28th, 2009
0

Re: Compiling error help please

Exactly right thank you.
Reputation Points: 10
Solved Threads: 0
Light Poster
JustLearning is offline Offline
31 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Database connection in c++
Next Thread in C++ Forum Timeline: automated ticket system! HELP!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC