I have been trying to use Makefile to be able to compile a single cpp file and then easily clean the generated executable. However, the Makefile code shown below doesn't compile the code with -g. As a result, I cannot use gdb on the executable. I am able to compile the code with -g flag successfully if I compile it using "g++ -g pairs_with_k_diff.cpp" in the command line. Would someone be kind enough to point out what my mistake is in the Makefile code shown below?
pawkdiff: pairs_with_k_diff.o
g++ pairs_with_k_diff.o -o pawkdiff
pawkdiff.o: pairs_with_k_diff.cpp
g++ -c -g pairs_with_k_diff.cpp
clean:
rm *.o pawkdiff
When I call make, I get the following output (As you can see, the -g flag is absent).
g++ -c -o pairs_with_k_diff.o pairs_with_k_diff.cpp
g++ pairs_with_k_diff.o -o pawkdiff
You have no rule for making pairs_with_k_diff.o, so the default rule is used.
Fix your second rule to make it work:
pairs_with_k_diff.o: pairs_with_k_diff.cpp
g++ -c -g pairs_with_k_diff.cpp
Or as an alternative:
pawkdiff: pawkdiff.o
g++ pairs_with_k_diff.o -o pawkdiff
pawkdiff.o: pairs_with_k_diff.cpp
g++ -c -g pairs_with_k_diff.cpp -o pawkdiff.o
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With