Skip to content

(winnie) Fix struct stat redefinition - reorder includes#3068

Merged
robe2 merged 1 commit intopgRouting:developfrom
Mohit242-bit:fix/winnie-struct-stat-redefinition
Feb 18, 2026
Merged

(winnie) Fix struct stat redefinition - reorder includes#3068
robe2 merged 1 commit intopgRouting:developfrom
Mohit242-bit:fix/winnie-struct-stat-redefinition

Conversation

@Mohit242-bit
Copy link
Contributor

@Mohit242-bit Mohit242-bit commented Feb 17, 2026

Fixes #3067 .

On Windows (MinGW), C++ headers like <sstream> must be included AFTER PostgreSQL headers to avoid struct stat redefinition errors.

The Problem
The include order in report_messages.cpp was:
#include "cpp_common/report_messages.hpp" // includes
extern "C" {
#include "c_common/postgres_connection.h" // PostgreSQL AFTER = broken
}
This causes MinGW's <sys/stat.h> to define struct stat first, then PostgreSQL's win32_port.h tries to redefine it → compilation error.
The Fix
Reorder includes so PostgreSQL headers come first:
extern "C" {
#include "c_common/postgres_connection.h" // PostgreSQL FIRST
#include "c_common/e_report.h"
}
#include <sstream> // C++ headers AFTER
#include "cpp_common/report_messages.hpp" // Project headers AFTER

@pgRouting/admins

Summary by CodeRabbit

  • Refactor
    • Internal code organization improvements with no functional changes to end-user behavior.

Copilot AI review requested due to automatic review settings February 17, 2026 19:09
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 17, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

Move of include "cpp_common/report_messages.hpp" from before the extern "C" block to after it in report_messages.cpp. No functional changes; resolves Windows build conflicts caused by C++ standard library header ordering with PostgreSQL C declarations.

Changes

Cohort / File(s) Summary
Include Order Fix
src/cpp_common/report_messages.cpp
Repositioned report_messages.hpp include from before to after the extern "C" block, preventing struct redefinition conflicts between MinGW system headers and PostgreSQL headers on Windows builds.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested reviewers

  • krashish8
  • sanak
  • cvvergara

Poem

🐰 Hop, hop, includes in a line,
Before, after, now they align!
Windows builds were in dismay,
Struct conflicts swept away! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change - reordering includes to fix struct stat redefinition on Windows/MinGW.
Linked Issues check ✅ Passed The PR addresses the linked issue #3067 by reordering includes in report_messages.cpp to place PostgreSQL headers before C++ headers, resolving the struct stat redefinition error on MinGW.
Out of Scope Changes check ✅ Passed The changes are focused solely on reordering includes in report_messages.cpp with no modifications to actual functionality or other files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Windows MinGW compilation error caused by incorrect include order in report_messages.cpp. On MinGW, C++ standard library headers like <sstream> must be included AFTER PostgreSQL headers to prevent struct stat redefinition conflicts between MinGW's <sys/stat.h> and PostgreSQL's win32_port.h.

Changes:

  • Reordered includes in report_messages.cpp to place PostgreSQL C headers before C++ standard library headers
  • Moved #include "cpp_common/report_messages.hpp" after #include <sstream> to maintain proper ordering

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Mohit242-bit
Copy link
Contributor Author

Hello @cvvergara ,
This PR addresses the Windows build failure (issue #3067) in report_messages.cpp caused by the struct stat redefinition.
I reordered the includes so that PostgreSQL headers are included before C++ headers—following the same approach you used in #2648 for similar issues.
The build now completes successfully on Windows (MSYS2 MinGW64).
Could you please review the changes and let me know if my solution aligns with pgRouting standards, or if there are any improvements I should consider? Your feedback would be greatly appreciated!

@robe2 robe2 merged commit 54c13c8 into pgRouting:develop Feb 18, 2026
65 of 66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Winnie can't build main, 4.0.1, and develop branch

2 participants

Comments