我是makefiles的新手.我从"使用GNU make管理项目"一书中学习了makefile创建和其他相关概念.makefile现在准备好了,我需要确保我创建的那个是好的.这是makefile
#Main makefile which does the build
#makedepend flags
DFLAGS =
#Compiler flags
#if mode variable is empty, setting debug build mode
ifeq ($(mode),release)
CFLAGS = -Wall
else
mode = debug
CFLAGS = -g -Wall
endif
CC = g++
PROG = fooexe
#each module will append the source files to here
SRC := main.cpp
#including the description
include bar/module.mk
include foo/module.mk
OBJ := $(patsubst %.cpp, %.o, $(filter %.cpp,$(SRC)))
.PHONY:all
all: information fooexe
information:
ifneq ($(mode),release)
ifneq ($(mode),debug)
@echo "Invalid build mode."
@echo "Please use 'make mode=release' or 'make mode=debug'"
@exit 1
endif
endif
@echo "Building on "$(mode)" mode"
@echo ".........................."
#linking the program
fooexe: $(OBJ)
$(CC) -o $(PROG) $(OBJ)
%.o:%.cpp
$(CC) $(CFLAGS) -c $< -o $@
depend:
makedepend -- $(DFLAGS) -- $(SRC)
.PHONY:clean
clean:
find . -name "*.o" | xargs rm -vf
rm -vf fooexe
Run Code Online (Sandbox Code Playgroud)
问题
任何帮助都会很棒.
Jon*_*ler 13
-g发布版本的标志不会自动坏,但如果您的代码产生核心转储,如果程序文件包含调试信息,则更容易构成核心转储的头部或尾部.调试信息的主要成本是程序文件中不需要加载到系统内存中的额外部分 - 运行时成本很小.
-g和-O.调试优化代码更加困难,但它为您提供(通常很重要的)性能优势.Art*_*yom 11
我会建议以下模式:
for debugger: -O0 -g -Wall
for development and internal release: -O2 -g -Wall
for release outside the company: -O2 -Wall
Run Code Online (Sandbox Code Playgroud)
理由:
-O2-g.但是,如果在这种模式下很难找到bug,你可以编译调试器-O0-g.-g在生产环境中使用代码是个好主意,因为如果某些内容崩溃,您可以获得更多信息.| 归档时间: |
|
| 查看次数: |
26099 次 |
| 最近记录: |