调用以对象向量作为参数的函数时出现链接错误
我有一个函数,它接受对象向量作为参数。函数头是:
void Evolve(vector <C_Agent> &population)
只要我不尝试实际调用该函数,代码就会正确编译。我这样调用它:
vector <C_Agent> AgentPopulation;
for(int q=0; q < x; q++)
AgentPopulation.push_back(C_Agent());
Evolve(AgentPopulation);
当我尝试调用它时,出现错误:
"Evolve(__gnu_debug_def::vector<C_Agent, std::allocator<C_Agent> >)", referenced from:
main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
我可以通过将参数更改为 int 而不是 C_Agent 向量来消除错误。
我尝试注释掉函数体,但这没有帮助。
I have a function that takes a vector of objects as it's argument. the function header is:
void Evolve(vector <C_Agent> &population)
the code compiles properly as long as I don't try to actually call the function. I call it like this:
vector <C_Agent> AgentPopulation;
for(int q=0; q < x; q++)
AgentPopulation.push_back(C_Agent());
Evolve(AgentPopulation);
when I try to call it, I get the error:
"Evolve(__gnu_debug_def::vector<C_Agent, std::allocator<C_Agent> >)", referenced from:
main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I can eliminate the error by changing the argument to an int instead of a vector of C_Agent.
I have tried commenting out the function body but that doesn't help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
binutils 的
nm
是你的朋友。它会告诉您main.o
正在尝试引用什么符号,以及另一个包含已编译函数定义的目标文件实际上正在公开什么符号。两者之间的不匹配将引导您找到不匹配的原因,从而找到问题的解决方案。您没有为万维网上的人们提供足够的信息来为您诊断此问题。nm
from binutils is your friend. It will tell you what symbolmain.o
is trying to reference and what symbol the other object file, with the compiled function definition in, is actually making public. The mismatch between the twain will lead you to the cause of the mismatch, and thence to the solution to your problem. You haven't provided enough information for people out here on the World Wide Web to diagnose this for you.