模式调试构建和设置 CFLAGS 变量的问题

Problems with mode debug build and setting the CFLAGS variable

我正在使用以下脚本构建以下 Artifex MuPDF 包:

#!/bin/bash
#########
# FILES #
#########
PACKAGE_NAME=mupdf-1.12.0-source
PACKAGE_TAR_FILE=${PACKAGE_NAME}.tar.xz
PACKAGE_FTP_SITE=https://mupdf.com/downloads/

####################################
# REMOVE OLD STUFF JUST TO BE SURE #
####################################
rm -rf build
rm -rf ${PACKAGE_NAME}
rm -rf ${PACKAGE_TAR_FILE}

#####################################
# Get source code for buggy package #
#####################################
wget ${PACKAGE_FTP_SITE}/${PACKAGE_TAR_FILE}

######################
# Unpack it here ... #
######################
tar xf ${PACKAGE_TAR_FILE}

#################
# Configure ... #
#################
cd ${PACKAGE_NAME}

###############
# Make it !!! #
###############
XCFLAGS="-g -O0" make

我使用 XCFLAGS 而不是 CFLAGS 来启用调试版本, 因为它在 makefile 中说的是:

Do not specify CFLAGS or LIBS on the make invocation line - specify XCFLAGS or XLIBS instead. Make ignores any lines in the makefile that set a variable that was set on the command line.

但是,当我启动 gdb 会话时,它说目标是在 没有 调试符号的情况下构建的:

$ gdb --args ./mupdf-1.12.0-source/build/release/mutool poster ~/Downloads/mutool_poster_crash
Reading symbols from ./mupdf-1.12.0-source/build/release/mutool...(no debugging symbols found)...done.

我怎样才能知道发生了什么事?谢谢!

I use XCFLAGS instead of CFLAGS to enable a debug build

这不是您制作调试版本的方式。查看 makefile 中的目标:

build ?= release

OUT := build/$(build)

default: all

...
...

all: libs apps

clean:
    rm -rf $(OUT)
nuke:
    rm -rf build/* generated $(NAME_GEN)

release:
    $(MAKE) build=release
debug:
    $(MAKE) build=debug

默认构建是发布类型构建,即

OUT := build/release

这就是你所做的:

./mupdf-1.12.0-source/build/release/mutool
                      ^^^^^^^^^^^^^      

发布版本删除了可执行文件:

mupdf-1.12.0-source$ XCFLAGS="-g -O0" make
...
mupdf-1.12.0-source$ file build/release/mutool 
build/release/mutool: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), \
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, \
BuildID[sha1]=a77cfe62290635ba12ae8327e24ee545c4dc1ded, \
stripped
^^^^^^^^

所以用-g -O0编译也没关系。调试信息已被删除。

像这样进行调试:

mupdf-1.12.0-source$ make debug

不会删除可执行文件:

mupdf-1.12.0-source$ file build/debug/mutool 
build/debug/mutool: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), \
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, \
BuildID[sha1]=c43e5aceb02812e1f77d2f00b7f75e4629128aac, \
with debug_info, not stripped
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

您当然仍然可以添加任何额外的 XCFLAGSXLIBS 选项。