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.
-bash-3.2$ gcc -o lemastsGCD lemastsGCD.cpp
/tmp/cca8g62Q.o: In function `__static_initialization_and_destruction_0(int, int)':
lemastsGCD.cpp:(.text+0x51): undefined reference to `std::ios_base::Init::Init()'
/tmp/cca8g62Q.o: In function `__tcf_0':
lemastsGCD.cpp:(.text+0x9a): undefined reference to `std::ios_base::Init::~Init()'
/tmp/cca8g62Q.o: In function `gcdr(int, int)':
lemastsGCD.cpp:(.text+0xb1): undefined reference to `std::cout'
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*)'
lemastsGCD.cpp:(.text+0xc7): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
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*)'
lemastsGCD.cpp:(.text+0xe8): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
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*)'
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> >&)'
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> >&))'
/tmp/cca8g62Q.o: In function `main':
lemastsGCD.cpp:(.text+0x166): undefined reference to `std::cout'
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
#include <iostream>
int gcdr(int a, int b); // recursive function declaration
int gcdi(int a, int b); // iterative function declaration
using namespace std;
int main(int argc, char *argv[]) // Command line arguments
{
if (argc != 4) // If the command line does not receive four
// arguments if statement is entered
{
cout << "\nProgram usage: program name.exe type of algorithm -r or -i integer integer\n";
// Statement to user that an error has occur ed
return -1; // Terminate program
}
int x,y,swap; // Variables to hold input integers from user
string GCDtype; // String variable to hold the type of function
// to be used.
GCDtype = argv[1]; // Variable to save the type of function to be run
swap = 0; // Integer variable used for swap
x = atoi(argv[2]); // Varable to hold first integer input
y = atoi(argv[3]); // Viable to hold second integer input
if (x <= y) // If statement to swap integers in the case
// that the first integer is larger than second
{
swap = x; // set swap variable equal to x
x = y; // set x equal to y
y = swap; // set y equal to swap variable
}
if (GCDtype == "-r") // If statement for recursive function
{
cout << "\nStarting recursion" << endl; // Inform user starting recursion
// start of recursion
cout << "gcd by recursive algorithm is " << gcdr(x, y)/* function call*/ << endl;
}
else if (GCDtype == "-i") // Else if for iterative function
{
// Run GCDi function
cout << "\ngcd by iterative algorithm is " << gcdi(x,y)/* function call*/ << endl;
}
else // Inform user that -r or -i was not entered
{
cout << "\nIncorrect use of program. Correct use is as follows\n";
cout << "Program Name.exe -r or -i integer integer" << endl;
}
return -1; // End program
}
int gcdr(int a, int b) // Function recursive
{
cout << "Finding gcd(" << a << "," << b << ")" << endl;
return ( b == 0 ? a : gcdr(b, a % b) ); // Run recursion until GCD is found
}
int gcdi(int a, int b) // Function iterative
{
int c; // Variable to hold b
while (b != 0) // Run while b does not equal zero
{
c = b;
b = a % b; // b now equals a mod b
a = c; // a now equals what b was
}
return a;
}