我正在尝试编译其他人的 C++ 代码。我自己有 0 个 C++ 经验。我在 MAC 上使用 g++ 来编译我收到的其中一个 .cpp 文件。当我执行 g++ main.cpp
时,出现 undefined symbol 错误。谷歌搜索时,答案似乎与文件之间的错误链接有关,但我不知道如何链接文件。
我怎样才能得到要编译的文件?我在下面粘贴了完整的代码。
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
最佳答案
我认为您只是试图编译整个程序的一部分。尝试 g++ *.cpp
如果还是不行,可能是因为你的程序需要一个外部库。
关于c++ - 编译c++文件时出错: Undefined symbols,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12748996/