使用库创建Makefile [英] Creating Makefile with libraries

查看:91
本文介绍了使用库创建Makefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用以下命令创建简单的Makefile?

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.

推荐答案

也许像

 # your Makefile

 #### variables
 RM= rm -vf
 CXX= g++
 CXXFLAGS= -Wall -g
 CPPFLAGS= -I/usr/include/opencv -I/usr/include/opencv2 
 LDLIBS= -lopencv_core -lopencv_imgproc -lopencv_highgui \
         -lopencv_ml -lopencv_video -lopencv_features2d \
         -lopencv_calib3d -lopencv_objdetect -lopencv_contrib \
         -lopencv_legacy -lv4l1 -lv4l2 -lv4lconvert 
 SOURCEFILES= sourc1.cpp sourc2.cpp sourc3.cpp 
 OBJECTFILES= $(patsubst %.cpp,%.o,$(SOURCEFILES))
 PROGNAME= yourexe

 ### rules
 .PHONY: all clean

 all: $(PROGNAME)
 $(PROGNAME): $(OBJECTFILES)
       $(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@

 clean:
       $(RM) $(OBJECTFILES) $(PROGNAME) 

随时适应. (您可能有头文件,并且需要将对象文件的依赖项添加到源文件和头文件中).如果知道 opencv ,也许可以使用 pkg-config .用选项卡替换规则中开头的许多空格. 仔细阅读 GNU make文档.

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.

如果有sourc2.cpp,并且有两个标头文件header1.hhheader2.hh,它们是#include -d的sourc2.cpp,则需要添加依赖项规则:

If you have sourc2.cpp and if you have two header files header1.hh and header2.hh which are #include-d by sourc2.cpp you'll need to add the dependency rule:

 sourc2.o: source2.cpp header1.hh header2.hh

有一种方法(通过传递诸如 -M 或-MDgcc通过适当的规则)以自动生成此类依赖项,请参见

and there is a way (by passing arguments like -M or -MD to gcc thru suitable rules) to get such dependencies automatically generated, see this question.

您可能要使用翻拍来调试Makefile -s(例如,作为remake -x).运行make -p以了解make

You may want to use remake to debug your Makefile-s (e.g. as remake -x). Run make -p to understand which rules are known to make

这篇关于使用库创建Makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆