Skip to content

fix: build and run on windows with MinGW#302

Open
tangxinfa wants to merge 1 commit intoHardySimpson:masterfrom
tangxinfa:fix-mingw-build
Open

fix: build and run on windows with MinGW#302
tangxinfa wants to merge 1 commit intoHardySimpson:masterfrom
tangxinfa:fix-mingw-build

Conversation

@tangxinfa
Copy link
Copy Markdown

@tangxinfa tangxinfa commented Jul 30, 2025

Fix build errors and segmentation fault on Windows

@tangxinfa tangxinfa changed the title fix: build with windows mingw fix: build and run on windows with MinGW Aug 4, 2025
Comment thread src/spec.c
time_stamp_convert_function(&(now_sec), time);
if (use_utc) {
gmtime_r(&(now_sec), time);
} else {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

On MinGW gmtime_r and localtime_r are inline functions, can't get function pointers

Comment thread src/spec.c
a_thread->event->last_pid = a_thread->event->pid;
a_thread->event->pid_str_len
= sprintf(a_thread->event->pid_str, "%u", a_thread->event->pid);
= sprintf(a_thread->event->pid_str, "%ld", (long)a_thread->event->pid);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Causes segmentation fault

Comment thread src/zc_xplatform.h
#define zlog_stat stat64
#elif defined(_WIN32)
#elif defined(_WIN32) && !defined(__MINGW32__)
#define zlog_fstat _fstat
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Conflict with MinGW defined macros

@F1sher
Copy link
Copy Markdown

F1sher commented Dec 26, 2025

Is there any progress on Windows MinGW porting?
platform : MSYS-3.6.5-0eeda3e1.x86_64

make
zlog-master/src/event.c:31:10: fatal error: sys/syscall.h: No such file or directory
31 | #include <sys/syscall.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [src/CMakeFiles/zlog.dir/build.make:149: src/CMakeFiles/zlog.dir/event.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:264: src/CMakeFiles/zlog.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

@tangxinfa
Copy link
Copy Markdown
Author

Porting zlog to windows is a heavy lift, even though there already did some
work, but works perfect is another story, most of the challenge come from the
file system API of the windows system.

For support Non-ASCII path we must use wide char version of api.

This means we must convert multi byte path to utf-16 string, and call wide char
version of apis, such as fopen must change to wfopen, change CreateFileA to
CreateFileW. For linux api, such as open, we must reimplement it with windows
api CreateFileW.

For support long path(exceed 260 characters), we must rewrite all posix and
linux file system api with a small set of windows api, and finally we should
implement a portable file system api layer with C, it's very painful.

Finally, most of the people will give up, especially just do it for one small project.

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.

2 participants