mirror of
https://github.com/jmcnamara/libxlsxwriter.git
synced 2026-05-15 14:15:54 -06:00
[GH-ISSUE #9] MinGW and libxlsxwriter produce invalid xlsx files on Windows Vista and above #9
Labels
No labels
awaiting user feedback
bug
cmake
cmake
docs
feature request
in progress
long term
medium term
medium term
pull-request
question
question
ready to close
short term
under investigation
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/libxlsxwriter#9
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @evgenybf on GitHub (Sep 30, 2015).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/9
Originally assigned to: @jmcnamara on GitHub.
I've build libxlsxwriter with MinGW (MSYS2 i686/x64)
gcc--version
gcc.EXE (Rev3, Built by MSYS2 project) 5.2.0
Test results:
https://gist.github.com/evgenybf/76283e50a20325964ca6#file-libxlsxwriter-test-results-on-windows
All files produced by the libxlsxwriter are invalid: inside of the archives lie empty files like [Content_Types].xml, .rels etc
@jmcnamara commented on GitHub (Sep 30, 2015):
Hi Evgeny,
Nice to hear from you again. Have you given up on Python. ;-)
The tests are all passing on Linux with gcc and clang (https://travis-ci.org/jmcnamara/libxlsxwriter) and also on MacOS.
Q1. I haven't used MinGW. Perhaps you can detail some steps to set it up and how to reproduce the issue?
The functional test are all failing with variants of "The system cannot find the path specified." so maybe the test runner isn't working in a MinGW/Windows environment.
Q2. Do the unit tests pass (
make test_unit)?Q3. Do the examples build (
make examples)? If so do you get an xlsx file when your execute one of them:./examples/hello?John
@evgenybf commented on GitHub (Sep 30, 2015):
Hi John,
I didn't expect that you remember me. I feel flattered. Thanks.
Python - forever! ;-). But now I am trying to take up the Go language and have plans to make simple bindings for generating xlsx files from Go.
I just got MSYS2 from http://sourceforge.net/projects/msys2/, updated your Makefiles to disable building of.so files, run make and that's it.
Almost all the tests failed because of empty value in the
gotvariable. For example, output of test_xmlwriter:It looks like that the issue caused by tmpfile(), as when I open a file manually and pass it to _xml_declaration() and others - all work fine. I suspect that the system cannot open a file for reading while it is opened for writing or perhaps there is needed fflush() call at the end.... In progress.
All the files produced by the example applications are broken.The generated xlsx files contain empty xml files inside.
@jmcnamara commented on GitHub (Sep 30, 2015):
That sounds like the issue. The code relies heavily on
tmpfile().I don't think I'll be able to help you on this since I've never used Msys2. If you find a fix let me know.
@evgenybf commented on GitHub (Sep 30, 2015):
file_sizeis always equal to -1.. moreover tmpfile() returns NULL! I should have checked it at first, sorry.Yes, I understand. I will try to resolve it by myself. Thank you for support.
@evgenybf commented on GitHub (Sep 30, 2015):
Some news:
According to https://msdn.microsoft.com/en-us/library/x8x7sakw.aspx tmpfile() on Windows (al least its Microsoft's implementation) creates temporary files in the root directory and therefore needs admin privileges...
All the tests passed when I run them as administrator...
@jmcnamara commented on GitHub (Sep 30, 2015):
Aargh! I should have thought of that first thing when you mentioned temp files and Windows.
That is the reason the Python and Perl modules have a tmpdir option to avoid that very problem:
@jmcnamara commented on GitHub (Sep 30, 2015):
Can you try settin the
TMPDIR,TEMP, orTMPenvironmental variable to control where the tmp dir is?@evgenybf commented on GitHub (Sep 30, 2015):
I've tried this:
..and for c:/temp as well and have got the same errors.
Now I'm looking into the sources of tmpfile() and _tmpnam_r(ptr, s) and don't see that they use any environment variables
https://github.com/msysgit/msys/blob/master/newlib/libc/stdio/tmpfile.c (not checked yet, but hope, that msys2 contains similar implementation)
https://github.com/msysgit/msys/blob/master/newlib/libc/stdio/tmpnam.c
The only function which reads $TMPDIR is _tempnam_r (ptr, dir, pfx), but the function is not called by tmpfile().
Btw, the constant _P_tmpdir used as a fallback has the following value:
stdio.h:
@jmcnamara commented on GitHub (Sep 30, 2015):
I'm only guessing because I don't know how the msys2 "shell" works but maybe the TMPDIR needs to be set in the Windows environment and not in the shell. What does the following print with and without the
set TMPDOR:Or perhaps it doesn't matter and, as you say, it doesn't have an effect on
tmpfile()either way.It seems odd that there isn't some way to workaround this in msys2. It seems like this would affect any application that calls
tmpfile().@evgenybf commented on GitHub (Oct 1, 2015):
I've tried it from the both places
Perl from msys prints
/tmpAnyway, microsoft documentation (link above) says that it needs adminstrator rights:
So, at least visual c++ compiler is out of the party despite pure ansi c.
Some libraries bypass it with their own implementation of tmpfile:
http://cgit.freedesktop.org/cairo/commit/?id=4fa46e3caaffb54f4419887418d8d0ea39816092
(not sure if it's still there though)
I've got there via this discussion: http://sourceforge.net/p/gnuwin32/discussion/74807/thread/903411c4/
@jmcnamara commented on GitHub (Oct 1, 2015):
That is interesting. If the a C program sees the same directory (and it probably does) then maybe you can map it to a writeable directory using the msys2
fstabfile. But maybe not based on your links.I don't disagree. And if that is sufficient for your needs then that is okay.
That's interesting. Thanks for the update.
If there is no further updates in a few days I will close this issue (or you can close it) as I don't want to have to change the
tmpfile()implementation. I'll suggest the Administrator workaround for anyone who needs it.@evgenybf commented on GitHub (Oct 1, 2015):
No, that's not sufficient for me at all. That was just a temporary workaround to make sure that tmpfile() is the culprit. On Linux nobody wants to run ordinary tools as root, don't they? I'll try to find a more descent solution...
@jmcnamara commented on GitHub (Oct 4, 2015):
Try something like the following:
It is available on the mkstemp branch. Change the template to suit your system.
It isn't ansi compatible however.
@evgenybf commented on GitHub (Oct 5, 2015):
Interesting! At first I was skeptical as it seemed (and actually "is" on Windows) useless to unlink/remove open files on Windows - the system doesn't let to do it. But mkstemp works well by itself - the temporary files get deleted just after they are closed. Thank you!
@jmcnamara commented on GitHub (Nov 7, 2015):
Closing. Use workaround if required.