Reputation: 159
I've created a header file reachability.h
and a source reachability.cc
in which I've declared a function map_nodes()
. However, I can't compile due to the error:
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
I double checked declarations of data structure that is passed to map_nodes()
and they are in the right place so that isn't the problem. I checked to #include "reachability.h"
in main and that's done. I also checked the parameter type and they match.
I can't figure out why the function isn't visible.
Here is an image of my workspace:
Upvotes: 0
Views: 54
Reputation: 75062
You didn't link reachability.cc
, where the function is defined. Link it to solve this probrem.
Example:
$ g++ -c reachability.cc
$ g++ -g lab1.o parser.o gate.o reachability.o -o run
($
is a prompt and you shouldn't enter it)
Upvotes: 0
Reputation: 76611
Asssuming reachability.cc was compiled to reachability.o, you need to link with it as well:
g++ -g lab1.o parser.o gate.o reachability.o -o run
Upvotes: 1