Ubuntu环境下配置Postgres 13时编译选项不被识别的问题
Ubuntu下编译PostgreSQL 13时Configure报错解决方法
问题描述
在Apache Age项目环境中,使用Ubuntu系统编译安装PostgreSQL 13,执行以下configure命令时失败:
./configure --prefix=/usr/local/pgsql-13 --enable-cassert --enable-debug CFLAGS="-glldb -ggdb -O0 -g3 -fno-omit-frame-pointer"
该命令在macOS可正常运行,但Ubuntu下报错。移除CFLAGS参数后configure能成功执行,但需要保留调试相关的CFLAGS选项。
命令执行报错输出
checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking which template to use... linux checking whether NLS is wanted... no checking for default port number... 5432 checking for block size... 8kB checking for segment size... 1GB checking for WAL block size... 8kB checking for gcc... gcc checking whether the C compiler works... no configure: error: in `/data/pg13/postgres': configure: error: C compiler cannot create executables See `config.log' for more details
config.log核心错误
从日志中可定位到关键报错:
configure:4004: gcc -glldb -ggdb -O0 -g3 -fno-omit-frame-pointer conftest.c >&5 gcc: error: unrecognized debug output level 'lldb'
问题原因
-glldb是Clang编译器(macOS默认编译器)专属选项,用于生成适配LLDB调试器的调试信息。而Ubuntu上使用的GCC编译器不支持该选项,这是导致编译失败的直接原因。
解决方法
修改CFLAGS参数,移除GCC不支持的-glldb,保留其他调试相关选项。调整后的configure命令如下:
./configure --prefix=/usr/local/pgsql-13 --enable-cassert --enable-debug CFLAGS="-ggdb -O0 -g3 -fno-omit-frame-pointer"
调试参数说明
-ggdb:生成适配GDB调试器的详细调试信息,Ubuntu下调试PostgreSQL推荐使用GDB-O0:关闭所有编译优化,确保调试时代码执行逻辑与源码完全一致-g3:生成额外调试信息(如宏定义),提升调试便利性-fno-omit-frame-pointer:保留栈帧指针,方便调试时回溯调用栈
验证步骤
- 执行调整后的configure命令,确认无报错
- 继续执行
make和make install完成编译安装 - 启动PostgreSQL后,可使用GDB进行调试工作
内容的提问来源于stack exchange,提问作者Ken W.
相关产品推荐
相关产品推荐

