Originally Posted by
Liiiim
Mind posting your code? It sounds like the first error is because you named your main function Main, with a capital 'm'. Remember C++ is case sensitive and your main function must be called main, otherwise it doesn't know where to start.
The second undefined reference is (I believe) because the linker can't find your library. Someone more experienced with gcc might tell you a better way to do this, but I think you can specify your library you want to bring in (CS106CPPLib.lib) with the '-l' switch, like this -
Code:
g++ -Wall -I /usr/local/include/cs106 -lCSE106CPPLib.lib -o test sample.cpp
Ok so I used what you suggested
And I get
/usr/bin/ld: cannot find -lCSE106CPPLib.lib
collect2: ld returned 1 exit status
So I tried both
Code:
export LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
And I'm still getting the same error.
This is the sample c++ I'm trying to compile
Code:
/*
* -----------------------------------------------------
* CS2S03/SE2S03, September 2011
* Assignment 1, Question 1
* File: PE0106.cpp
* -----------------------------------------------------
* This program reads an integer and then displays the
* number that has the same digits in the reverse order.
* -----------------------------------------------------
*/
#include "genlib.h"
#include "simpio.h"
#include <iostream>
/* Private function prototypes */
long DigitReverse(long n);
/* Main program */
int main() {
long n;
cout << "This program reverses the digits in an integer." << endl;
while (true) {
cout << "Enter a positive integer: ";
n = GetLong();
if (n > 0) break;
cout << "Try again." << endl;
}
cout << "The reversed integer is: " << DigitReverse(n) << endl;
return 0;
}
/*
* Function: DigitReverse
* Usage: rev = DigitReverse(n);
* -----------------------------------------------------
* This function returns the integer that has the same
* digits as n but in reverse order
*/
long DigitReverse(long n) {
long reverse = 0;
while (n > 0) {
reverse = reverse * 10 + (n % 10);
n = n / 10;
}
return reverse;
}
Bookmarks