我通过xcode安装了gcc但是在尝试编译文件时遇到了这个错误:
sanjay$ g++ main.cpp
Undefined symbols for architecture x86_64:
"Fraction::Fraction(int, int)", referenced from:
MathAssignTest() in cck2LKpO.o
BinaryMathTest() in cck2LKpO.o
RelationTest() in cck2LKpO.o
BasicTest() in cck2LKpO.o
"Fraction::operator/=(Fraction const&)", referenced from:
MathAssignTest() in cck2LKpO.o
"Fraction::operator-=(Fraction const&)", referenced from:
MathAssignTest() in cck2LKpO.o
"Fraction::operator*=(Fraction const&)", referenced from:
MathAssignTest() in cck2LKpO.o
"Fraction::operator--(int)", referenced from:
MathAssignTest() in cck2LKpO.o
"Fraction::operator--()", referenced from:
MathAssignTest() in cck2LKpO.o
"Fraction::operator+=(Fraction const&)", referenced from:
MathAssignTest() in cck2LKpO.o
"Fraction::operator++(int)", referenced from:
MathAssignTest() in cck2LKpO.o
"Fraction::operator++()", referenced from:
MathAssignTest() in cck2LKpO.o
"operator/(Fraction const&, Fraction const&)", referenced from:
BinaryMathTest() in cck2LKpO.o
"operator==(Fraction const&, Fraction const&)", referenced from:
RelationTest() in cck2LKpO.o
"operator>=(Fraction const&, Fraction const&)", referenced from:
RelationTest() in cck2LKpO.o
"operator>(Fraction const&, Fraction const&)", referenced from:
RelationTest() in cck2LKpO.o
"operator<=(Fraction const&, Fraction const&)", referenced from:
RelationTest() in cck2LKpO.o
"operator<<(std::basic_ostream<char, std::char_traits<char> >&, Fraction const&)", referenced from:
MathAssignTest() in cck2LKpO.o
BinaryMathTest() in cck2LKpO.o
RelationTest() in cck2LKpO.o
BasicTest() in cck2LKpO.o
"operator<(Fraction const&, Fraction const&)", referenced from:
RelationTest() in cck2LKpO.o
"operator-(Fraction const&, Fraction const&)", referenced from:
BinaryMathTest() in cck2LKpO.o
"operator*(Fraction const&, Fraction const&)", referenced from:
BinaryMathTest() in cck2LKpO.o
"operator!=(Fraction const&, Fraction const&)", referenced from:
RelationTest() in cck2LKpO.o
"operator+(Fraction const&, Fraction const&)", referenced from:
BinaryMathTest() in cck2LKpO.o
"operator>>(std::basic_istream<char, std::char_traits<char> >&, Fraction&)", referenced from:
BasicTest() in cck2LKpO.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
我该如何解决这个问题? 我很确定我的g ++编译器已经正确设置,因为它适用于不同文件夹中的文件。 PLease帮我解决这个问题。我是这种语言的初学者,我正在尽我所能去理解。
答案 0 :(得分:0)
您需要将包含Fraction类的cpp文件添加到命令行。像这样的东西
g++ main.cpp Fraction.cpp
希望有所帮助。 :)