You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下PostgreSQL源码编译make命令报错求助

Fixing "unknown type name '_locale_t'" Error When Building PostgreSQL 9.5.10 with MinGW/msys on Windows

Hey there, I’ve run into similar quirks with older PostgreSQL versions on MinGW, so let’s break down what’s going on and how to fix it.

What’s Causing the Error?

The root issue is a mismatch between PostgreSQL 9.5’s locale type definition and your MinGW environment. The code in pg_config_os.h tries to define locale_t as _locale_t, but MinGW doesn’t recognize the _locale_t type by default—this is a compatibility gap between the older PostgreSQL codebase and how MinGW handles locale-related types.

Solutions to Try

1. Modify the PostgreSQL Header File (Recommended)

This directly fixes the mismatched type definition without workarounds:

  • Navigate to your PostgreSQL source directory, open src/include/pg_config_os.h
  • Find line 333 (the line with #define locale_t _locale_t)
  • Replace that line with a conditional check to skip the definition for MinGW:
    #ifndef __MINGW32__
    #define locale_t _locale_t
    #endif
    
  • Save the file, run make clean to clear old build artifacts, then re-run make

2. Use a Compile-Time Workaround

If you don’t want to edit source files, you can override the locale_t definition during the build process:

make CPPFLAGS="-Dlocale_t=void*"

This forces the compiler to treat locale_t as a generic pointer type, bypassing the missing _locale_t error. Note: This is a temporary fix and might cause subtle locale-related issues later, so use it only if the first method doesn’t work.

3. Upgrade Your Tools or PostgreSQL Version

PostgreSQL 9.5 is quite old (released in 2016), and newer MinGW versions have changed how locale types are handled. Consider:

  • Upgrading MinGW to the latest stable release (make sure you install the full development toolchain, including all required libraries)
  • Switching to a newer PostgreSQL version (12 or later)—these releases have far better Windows/MinGW compatibility and likely resolve this locale issue out of the box.

Quick Pre-Build Checks

  • Double-check that your MinGW/msys environment has all required dependencies (you already included OpenSSL and UUID paths, which is great)
  • Always run make clean before re-trying the build to avoid leftover files from failed attempts.

内容的提问来源于stack exchange,提问作者roopteja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:56:08