How can I create a simple Makefile using the below command?
g++ -Wall -I/usr/include/opencv -I/usr/include/opencv2 -L/usr/lib/ -g -o exe sourc1.cpp sourc2.cpp sourc3.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lv4l1 -lv4l2 -lv4lconvert -pthread
I referenced this link but I am getting confused.
Maybe something like
Feel free to adapt. (You probably have header files, and you need to add dependencies of object files to source and to header files). Perhaps use pkg-config if it knows about opencv. Replace the initial many spaces in the rules with a tab. Read carefully GNU make documentation.
If you have
sourc2.cpp
and if you have two header filesheader1.hh
andheader2.hh
which are#include
-d bysourc2.cpp
you'll need to add the dependency rule:and there is a way (by passing arguments like -M or
-MD
togcc
thru suitable rules) to get such dependencies automatically generated, see this question.You may want to use remake to debug your
Makefile
-s (e.g. asremake -x
). Runmake -p
to understand which rules are known tomake