CPPUTestMakeFile帮助链接 [英] CPPUTestMakeFile Help linking

查看:115
本文介绍了CPPUTestMakeFile帮助链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个makefile,它可以为CppUTest创建一个exe.它找不到标题,我做错了什么?第一次制作Makefile,而不是100%确定我在做什么.

I am trying to make a makefile, which can make an exe for CppUTest. It can not find the headers, what have I done wrong? First time making a makefile, not 100% sure what I'm doing.

#The compiler to use
CC = g++
LINK = -g -pedantic -Wall -lstdc++ -lpthread -ldl -lm -Wl,-rpath,.
COMPILE = -g -O3 -D_THREAD_SAFE -pedantic -Wall -c -Wno-deprecated 
#Name of the EXE file to create.
EXE    = ./Tests
SRCS   = $(shell ls *.cpp)
OBJS   = $(subst .cpp,.o,$(SRCS))
#Extra flags to give to the C compiler.
CFLAGS = 
#Libraries to include
LIBS= -lCppUTestExt -lCppUTest -lm 
#Extra flags to give to the C++ compiler. 
CXXFLAGS = -I/home/mg/DS-5-Workspace/Tests/include       
#Extra flags to give to compilers when they are supposed to invoke the linker, ‘ld’, 
#such as -L. Libraries (-lfoo) should be added to the LDLIBS variable   
#instead.            

LDFLAGS = -L/home/mg/DS-5-Workspace/Tests/cpputest/lib
#Extra flags to give to the C preprocessor and programs that use it (the C and  
#Fortran     compilers). 

CPPFLAGS = 

.SUFFIXES: .o .cpp

.cpp.o:
$(CC) $(CFLAGS) $(CXXFLAGS) $(LDFLAGS) $(COMPILE) $(LIBS) $<

all: $(OBJS)
$(CC) $(CFLAGS) $(CXXFLAGS) $(LDFLAGS) $(LIBS) $(OBJS) -o $(EXE) $(LINK)


-include depend.mak


depend:
g++ -MM $(SRCS) > depend.mak


#static:
#ar -crvs $(a) $(OBJS)


#shared: $(OBJS)
#$(CC) -shared -Wl,-soname -lc -o $(so) $(OBJS) 

clean:
rm -rf $(OBJS) depend.mak $(EXE) $(so) $(a)

我遇到以下错误:

错误:CppUTest/CommandLineTestRunner.h:没有此类文件或目录

error: CppUTest/CommandLineTestRunner.h: No such file or directory

推荐答案

好吧,您正在混淆很多事情.

Well, you're mixing up a lot of things.

让我们清理一下,只保留所需的内容:

Let's clean this up and keep only what is needed :

EXE         :=  Tests

SRC         :=  $(wildcard *.cpp)

OBJ         :=  $(SRC:%.cpp=obj/%.o)

DEP         :=  $(OBJ:.o=.d)

LDLIBS      :=  -lCppUTestExt -lCppUTest -lm -lstdc++ -lpthread -ldl

LDFLAGS     :=  -L/home/mg/DS-5-Workspace/Tests/cpputest/lib
LDFLAGS     +=  -Wl,-rpath,.

CPPFLAGS    :=  -I/home/mg/DS-5-Workspace/Tests/include
CPPFLAGS    +=  -MMD -MP -D_THREAD_SAFE

CXXFLAGS    :=  -W -Wall -Wno-deprecated -pedantic -O3 -g

.PHONY: all clean fclean re

all:    obj $(EXE)

clean:
    $(RM) -r obj

fclean: clean
    $(RM) $(EXE)

re: fclean all

-include $(DEP)

$(EXE): $(OBJ)
    $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@

# %.a:  $(OBJ)
#   $(AR) crvs $@ $^
#   ranlib $@

# %.so: CXXFLAGS += -fPIC
# %.so: $(OBJ)
#   $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@

obj:
    @mkdir -p $@

obj/%.o:    %.cpp
    $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<

一些解释:

  • 避免使用$(shell ...)函数,因为如果使用=运算符而不是:=运算符赋值该变量,则每次调用该变量时都会执行该函数.

  • Avoid the $(shell ...) function, because it'll be executed each time the variable is called if assigned with the = operator instead of := operator.

$(CC)是一个包含ccgcc的内置变量(应等效).使用内置的$(CXX)来使用g++.

$(CC) is a built-in variable containing cc or gcc (should be equivalent). Use the built-in $(CXX) to use g++.

-g-pedantic-O3-Wno-deprecated-Wall是编译器标志,它们应位于CFLAGS(对于C)或CXXFLAGS(对于C ++)中-in变量.

-g, -pedantic, -O3, -Wno-deprecated and -Wall are compiler flags, they should be in the CFLAGS (for C) or CXXFLAGS (for C++) built-in variables.

-I <path>-D_THREAD_SAFE是预处理器标志,因此应位于CPPFLAGS内置变量中.

-I <path> and -D_THREAD_SAFE are preprocessor flag, thus should be in the CPPFLAGS built-in variable.

-MMD -MP将为每个.o文件自动生成依赖项文件(扩展名.d).您可以在此处了解详情.

-MMD -MP will auto-generate dependency files (.d extension) for each .o file. You can read more here.

.cpp.o:是后缀规则,并且后缀规则是为make定义隐式规则的老式方法.您应该仅依靠这些隐式规则使已经知道的或以现代方式成为自己的规则.

.cpp.o: is a suffix rule, and suffix rules are the old-fashioned way of defining implicit rules for make. You should just rely upon these implicit rules make already know about or make your own the modern way.

您不需要为如此广泛使用的目标自己定义.SUFFIXES:. 在make读取任何makefile之前,将变量SUFFIXES定义为默认后缀列表. Make 3.82默认情况下定义以下后缀:

You don't need to define .SUFFIXES: by yourself for such widely used targets. The variable SUFFIXES is defined to the default list of suffixes before make reads any makefiles. Make 3.82 defines these suffixes by default :

.SUFFIXES: .out .a .ln .o .c .cc .C .cpp .p .f .F .m .r .y .l .ym .yl .s .S .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo .w .ch .web .sh .elc .el

如果有任何疑问,请继续.

If you have any questions, go on.

这篇关于CPPUTestMakeFile帮助链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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