Currently I have a program that has a main.cpp
, linked_queue.cpp
and a linked_queue.h
, and I am trying to write a simple Makefile, but I am running into a linker issue.
In main.cpp
I have included the header file, #include"linked_queue.h"
, but I am getting a linker error. The following is there error on my machine:
clang++ -g3 -std=c++1z -Wconversion -Wall -Werror -Wextra -pedantic -c linked_queue.cpp
clang++ -g3 -std=c++1z -Wconversion -Wall -Werror -Wextra -pedantic -c main.cpp
clang++ -g3 -std=c++1z -Wconversion -Wall -Werror -Wextra -pedantic linked_queue.o main.o -o main
Undefined symbols for architecture x86_64:
"LinkedQueue<int>::push(int)", referenced from:
_main in main.o
"LinkedQueue<int>::~LinkedQueue()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This is the current contents of my Makefile:
main: linked_queue.o main.o
clang++ -g3 -std=c++1z -Wconversion -Wall -Werror -Wextra -pedantic linked_queue.o main.o -o main
linked_queue.o: linked_queue.cpp linked_queue.h
clang++ -g3 -std=c++1z -Wconversion -Wall -Werror -Wextra -pedantic -c linked_queue.cpp
main.o: main.cpp linked_queue.h
clang++ -g3 -std=c++1z -Wconversion -Wall -Werror -Wextra -pedantic -c main.cpp
clean:
rm -rf *.o *.dSYM main
I thought I included all the dependencies. Any thoughts on what I have missed?