0

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 ++​​コンパイラは、別のフォルダ内のファイルに対して機能するため、適切に設定されていると確信しています。これで私を助けてください..私はこの言語の初心者で、理解するために最善を尽くしています.

4

1 に答える 1

0

Fraction クラスを含む cpp ファイルをコマンド ラインに追加する必要があります。このようなもの

g++ main.cpp Fraction.cpp

それが役立つことを願っています。:)

于 2013-04-27T10:29:43.223 に答える