如何解决这个问题? C++编译器设置

问题描述 投票:0回答:1

我通过 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++ 编译器已正确设置,因为它适用于不同文件夹中的文件。请帮助我解决这个问题。我是这门语言的初学者,正在尽力理解。

c++ gcc installation g++
1个回答
0
投票

您需要将包含 Fraction 类的 cpp 文件添加到命令行中。像这样的东西

g++ main.cpp Fraction.cpp

希望有帮助。 :)

© www.soinside.com 2019 - 2024. All rights reserved.