编译c ++文件时出错:未定义的符号

Nie*_*ein 0 c++ linker g++

我正在尝试编译其他人的C++代码.我自己有0个C++经验.我在MAC上使用g ++来编译我收到的一个.cpp文件.当我这样做时,g++ main.cpp我得到一个未定义的符号错误.当谷歌搜索答案似乎是文件之间的错误链接,但我不知道如何链接文件.如何让文件编译?我粘贴了下面的完整代码.

Undefined symbols:
  "initializeFitness()", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Grid::GetNeighbourhood(int, int, std::vector<Agent**, std::allocator<Agent**> >&)", referenced from:
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
  "Grid::Grid()", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Reaper::GetAgentToKill()", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Cupid::GetRandomBreeder()", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Reaper::Select()", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Grid::~Grid()", referenced from:
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
  "Breeder::Breed(Agent**, Agent**)", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Cupid::Select()", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Cupid::GetEmptyCell()", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Agent::GetType()", referenced from:
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
  "Breeder::ProcessNeighbourhood(std::vector<Agent**, std::allocator<Agent**> > const&)", referenced from:
      runEvolution()     in ccZXBTDH.o
  "FateAgent::GetGenome(double*)", referenced from:
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
  "Cupid::GetParents()", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Agent::IncreaseAge()", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Grid::GetAgent(int, int)", referenced from:
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
  "FateAgent::GetSelectedCount()", referenced from:
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
  "Breeder::GetGenome(double*)", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Agent::GetFitness()", referenced from:
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
      runEvolution()     in ccZXBTDH.o
  "Agent::~Agent()", referenced from:
      runEvolution()     in ccZXBTDH.o
  "Grid::DoMovement()", referenced from:
      runEvolution()     in ccZXBTDH.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

tom*_*ahh 5

我想你只是想编译整个程序的一部分.尝试g++ *.cpp
如果它仍然无法工作,可能是因为您的程序需要一个外部库.