今天再用addr2line 时, 发现不能给出行号,原来是gcc/g++编译器 -fPIC 引起的,参考:
处理segment fault 的一种方法_hjjdebug的博客-CSDN博客_segmentfault
编译需要加入-no-pie 就可以看到源码信息了.
如果在qt 工程里如何控制编译选项呢, 主要是自己试出来的,记录一下:
参考了:
1. qmake -d 有 lots of message 输出, 可参考.
2. Makefile 内容
3. 网络
发现关键是修改 QMAKE_CXXFLAGS, QMAKE_LDFLAGS 才能够改变到Makefile 中的CXXFLAGS,LDFLAGS, 给出一个示例来如下, 请参考注释.
######################################################################
# Automatically generated by qmake (3.1) Tue Apr 5 16:31:59 2022
######################################################################
TEMPLATE = app
TARGET = crash
INCLUDEPATH += .
QT-=core gui
CONFIG+=debug
# 想改变CXXFLAGS, 采用如下的方式
QMAKE_CXXFLAGS += -no-pie
QMAKE_CXXFLAGS_APP -= -fPIC
# 想改变LFLAGS 选项?
QMAKE_LFLAGS += -no-pie
# You can make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# Please consult the documentation of the deprecated API in order to know
# how to port your code away from it.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# Input
SOURCES += main.cpp
生成Map 文件:
QMAKE_LFLAGS += -Wl,-Map,file_name.map