CPPUTestMakeFile 帮助链接

问题描述 投票:1回答:1

我试图制作一个makefile,可以为CppUTest制作一个exe。 它找不到头文件,我做错了什么? 第一次做makefile,不是100%确定我在做什么。

#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)

我有以下错误。

错误:"CppUTestCommandLine"。CppUTestCommandLineTestRunner.h: 没有这样的文件或目录

makefile gnu-make
1个回答
2
投票

好吧,你混淆了很多东西。

让我们清理一下,只保留需要的东西。

EXE      := Tests
SRC_DIR  := .
OBJ_DIR  := obj
SRC      := $(wildcard $(SRC_DIR)/*.cpp)
OBJ      := $(SRC:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)

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

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

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

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

.PHONY: all clean fclean re

all: $(EXE)

clean:
    $(RM) -f -r $(OBJ_DIR)

fclean: clean
    $(RM) -f $(EXE)

re: fclean all

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

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

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

$(OBJ_DIR):
    @mkdir -p $@

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

-include $(OBJ:.o=.d)

一些解释。

  • 避免使用 $(shell ...) 函数,因为如果用 = 操作员而不是 := 操作符。

  • $(CC) 是一个内置变量,包含 ccgcc 应该是等价的)。使用内置的 $(CXX) 使用 g++.

  • -g, -pedantic, -O3, -Wno-deprecated-Wall 是编译器标志,它们应该在 CFLAGS (对C)或 CXXFLAGS (对于C++)内置变量。

  • -I <path>-D_THREAD_SAFE 是预处理器的标志,因此应该是在 CPPFLAGS 内置变量。

  • -MMD -MP 将自动生成依赖文件(.d 分机)的每个 .o 文件。您可以 阅读更多.

  • .cpp.o: 是一个后缀规则,而 后缀规则是老式的定义隐性规则的方式,用于使. 你应该只是依靠这些隐性规则使已经知道的或使你自己的现代方式。

  • 你不需要定义 .SUFFIXES: 由你自己来处理这些广泛使用的目标。变量SUFFIXES被定义为make读取任何makefile之前的默认后缀列表。 Make 3.82默认定义了这些后缀 。

    .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
    

如果你有任何问题,请继续。

© www.soinside.com 2019 - 2024. All rights reserved.