我正在学习C++,我得到了这个错误:
Undefined symbols:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status我的代码是
#include <stdlib.h>
#include <iostream>
class Fraction {
private:
int num, den;
public:
void set(int n, int d) {num=n; den=d; normalize();}
int get_num(){return num;}
int get_den(){return den;}
private:
void normalize();
int gcf(int a, int b);
int lcm(int a, int b);
};
void Fraction::normalize() {
if (den == 0 || num == 0) {
num = 0;
den = 1;
}
if (den < 0) {
num *= -1;
den *+ -1;
}
int n = gcf(num, den);
num = num / n;
den = den / n;
}
int Fraction::gcf(int a, int b) {
if (a % b == 0)
return abs(b);
else return gcf(b, a % b);
}
int Fraction::lcm(int a, int b) {
return(a / gcf(a, b)) * b;
}如果有帮助的话,我使用的是带有命令g++ -o的GCC。
任何帮助都非常感谢!
发布于 2011-08-26 06:30:47
您的main函数在哪里?C++中的每个“普通”程序都是从main函数开始的,这就是为什么链接器要寻找一个函数。你还没有提供它。因此出现了错误。
https://stackoverflow.com/questions/7197982
复制相似问题