MSVC compatibility

Thierry
2012-04-19
2014-05-16
  • Thierry
    Thierry
    2012-04-19

    Hi,
    I've made a patch for liblzma to build with MSVC. The main reason fr that is that the provided liblzma.a doesn't work too well with MSVC2011 (it complains about it not compiled with MSVC and not being compatible with their exception hanlding).
    The patch is quite big and is basically a port of liblzma to C89. Is someone interested?

     
  • Lasse Collin
    Lasse Collin
    2012-04-29

    Using liblzma.a with MSVC was kind of ugly but I understood that with earlier MSVC versions it worked fine and without warnings. I will update README-Windows.txt.

    It seems, that among the compilers in use today, only MSVC and GCC 2 don't support enough C99. GCC 2 is getting more and more rare, and MS isn't interested in supporting modern C. So I'm not so interested in limiting myself to older standards. On the other hand, it isn't a good situation if people have to keep porting XZ Utils to old compilers again and again.

    Why do you need static liblzma instead of a DLL? Self-extracting installers are one situation that I'm aware but is there anything else? Installation program usually needs only decompression. I know one person who uses XZ Embedded in an installer because that is C89 and it is also small. Another good alternative is LZMA SDK which supports the .xz format and is compatible with MSVC.

     
  • Gilles Vollant
    Gilles Vollant
    2012-08-07

    I'm very interrested. I'm compiling software with Visual Studio, and building a monolithic executable is important for me. Can you publish it?

     
  • Gilles Vollant
    Gilles Vollant
    2012-08-29

    There is another need for a MSVC compilation : WinRT (for Windows metro application, including in ARM tablet Windows and next Windows phone 8) can only uses Visual Studio 2012

     
  • eXpl0it3r
    eXpl0it3r
    2012-09-04

    I would also be highly interested into such a port.
    IMHO static linking makes very much sense for many applications, since you'd end up with one executable that can be moved around freely, where as dynamic linkage would require to copy around liblzma.dll too.
    If only Windows had some package managing like Linux system, things would be a bit easier…
    @thierryba: Would it be possible to publish it?

     
  • Gilles Vollant
    Gilles Vollant
    2013-05-05

    This is also useful for compiling in Windows Phone 8 project

     
  • Lasse Collin
    Lasse Collin
    2013-11-22

    Has anyone tried building liblzma with MSVC 2013 yet? If someone wants to test, I recommend trying with 5.1.3alpha because it has some threading code and thus more things to test.

     
  • fanc999
    fanc999
    2013-12-23

    Hello,

    I tried to build xz-5.0.5 and basically albeit some MSVC 2013 weirdness I was able to get it to work with some small changes. Apparently it does not like things like this,for example (oddly):


    int aa=345;
    if (expr == TRUE)
    aa = 456;
    int bb = aa + 111;

    So, changing that to this will work:


    int aa=345;
    if (expr == TRUE)
    {
    aa = 456;
    }
    int bb = aa + 111;

    So, that was the type of small changes for liblzma to build on MSVC 2013. However, since xz.exe uses the posix gettimeofday() function and snprintf(), I used the kdewin implementation of these functions so that xz.exe will build. By running the tests on the built DLL, it seems that all is well there in both x86 and x64 flavors, when linked to MSVCRT120.dll (/MD).

    Hope this helps.

     
    Last edit: fanc999 2013-12-23
  • Lasse Collin
    Lasse Collin
    2013-12-29

    Thanks!

    Seems that a few other people have noticed the same MSVC bug. It's a fairly new report so with huge luck it might even get fixed. On the other hand, if there aren't too many of those issues in XZ Utils, it may be OK to workaround the MSVC bug.

    I think getting liblzma buildable with MSVC is more important than building also xz. I've understood that people want MSVC support for liblzma because that will make it easier to use liblzma when the rest of the application is built with MSVC anyway. xz is a standalone program so MSVC support doesn't matter much, but if the only issues are gettimeofday() and snprintf() it sounds quite good already.

     
  • Gilles Vollant
    Gilles Vollant
    2014-04-06

    hello,
    if anyone has already build a project and fix to compile liblzma with msvc2013, can he public it?

     
  • Lasse Collin
    Lasse Collin
    2014-04-08

    The MSVC bug linked above has been marked as fixed, so I think liblzma from the current xz.git should compile with MSVC 2013 if the latest updates to MSVC have been applied. Note that only liblzma is supported; building the command line tools isn't. There's a config.h for MSVC 2013 in the windows directory. MSVC project files are still missing so you need to pick the files by hand, but that will be fixed.

    I don't know yet if support for building the command line tools with MSVC will be included. I guess in most cases it's liblzma for which MSVC support is wanted.

     
  • Gilles Vollant
    Gilles Vollant
    2014-04-14

    what update of vs2013 is needed ? update 1?

     
  • Lasse Collin
    Lasse Collin
    2014-04-15

    I think it's update 2 which seems to still be RC, sorry. For earlier VS2013 a workaround for the bug mentioned above is needed. I don't have a ready-made patch for the current xz.git. Before the final version of VS2013 update 2 is out, you could try https://github.com/Garen/xz. Some of the VS2013 fixes made in xz.git are from the same author.

     
  • Gilles Vollant
    Gilles Vollant
    2014-04-19

    https://github.com/Garen/xz was exxactly what I need :-)

    I uploaded at http://gvollant.free.fr/update_xz2013.zip some file modification :
    filter_buffer_decoder.c, filter_buffer_encoder.c, stream_buffer_decoder.c, stream_buffer_encoder.c modification (adding { and }) for VS2013 update 1, and a project for static library, with same tree for source than files

     
  • Gilles Vollant
    Gilles Vollant
    2014-05-14

    I just used config.h from https://github.com/Garen/xz, and both src/common/sysdefs.h and src/liblzma/check/sha256.c from last git repository http://git.tukaani.org/xz.git , and compile liblzma for both encoding/decoding xz stream with VS2013 update 2

     
  • Lasse Collin
    Lasse Collin
    2014-05-16

    I think it should work to build liblzma from xz.git with windows/config.h without modifying any files. If it doesn't, it probably is something short and simple to fix, so I'd like to know what to fix. Thanks! I'll ask Garen about this too on IRC.