gpt4 book ai didi

c++ - "Undefined Reference"我已经声明和定义并#included 的函数错误

转载 作者:行者123 更新时间:2023-11-28 05:46:42 25 4
gpt4 key购买 nike

我创建了一个头文件 reachability.h 和一个源文件 reachability.cc,我在其中声明了一个函数 map_nodes()。但是,由于错误,我无法编译:

g++ -g lab1.o parser.o gate.o -o run
lab1.o: In function `main':
/home/ubuntu/workspace/ECE597/Lab1/lab1.cc:24: undefined reference to `map_nodes(std::vector<gate*, std::allocator<gate*> >)'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1

我仔细检查了传递给 map_nodes() 的数据结构声明,它们位于正确的位置,所以这不是问题所在。我检查了 main 中的 #include "reachability.h" 就完成了。我还检查了参数类型,它们匹配。

我不明白为什么函数不可见。

这是我工作区的图片:

ide-undef-err.png

最佳答案

假设 reachability.cc 被编译为 reachability.o,您还需要链接它:

g++ -g lab1.o parser.o gate.o reachability.o -o run

关于c++ - "Undefined Reference"我已经声明和定义并#included 的函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36077060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com