我正在学习 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;
}
如果有帮助的话,我正在使用 GCC 和命令 g++ -o
。
非常感谢任何帮助!
最佳答案
main
函数在哪里? C++ 中的每个“普通”程序都从 main
函数开始,这就是链接器寻找一个的原因。你没有提供。因此错误。
关于c++ - 奇怪的 "Undefined symbols"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7197982/