www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - BZ2 library

reply stunaep <admin pea2nuts.com> writes:
I'm really having a hard time using bzp (and later I need gzip 
and lzma).

So I added this bzip2 D interface to my DUB dependencies
     "dependencies" : {
         "bzip2": "~>0.1.0"
     }

I downloaded the bzip2 source code and compiled it for windows 
32bit (will 64 bit work with dmd2?). Then I used coffimplib.exe 
to convert the .lib file from coff to omf. From there I added 
this code:
     pragma(lib, "libbzip2OMF.lib");

Now when I run the program it terminates with exit code 
-1073741515 and will not print or do anything written in the 
program. Am I doing the right things? This is the first time I've 
ever done this and I was unable to find any useful help on this 
subject, so some help would be very much appreciated. Thanks.
Mar 11 2016
next sibling parent reply Mike Parker <aldacron gmail.com> writes:
On Saturday, 12 March 2016 at 05:16:37 UTC, stunaep wrote:
 I'm really having a hard time using bzp (and later I need gzip 
 and lzma).

 So I added this bzip2 D interface to my DUB dependencies
     "dependencies" : {
         "bzip2": "~>0.1.0"
     }

 I downloaded the bzip2 source code and compiled it for windows 
 32bit (will 64 bit work with dmd2?).
Yes, as long as you have the Microsoft toolchain installed. You can use the COFF format then.
 Then I used coffimplib.exe to convert the .lib file from coff 
 to omf. From there I added this code:
     pragma(lib, "libbzip2OMF.lib");
With the Microsoft toolchain installed, you don't need to do any conversion. You can use the MS linker with the -m32mscoff for 32-bit and -m64 for 64-bit. In both cases, DMD will use the MS linker instead of the default OPTLINK.
 Now when I run the program it terminates with exit code 
 -1073741515 and will not print or do anything written in the 
 program. Am I doing the right things? This is the first time 
 I've ever done this and I was unable to find any useful help on 
 this subject, so some help would be very much appreciated. 
 Thanks.
Did you compile bzip2 with MinGW? If so, try compiling with Visual Studio instead.
Mar 11 2016
parent reply stunaep <admin pea2nuts.com> writes:
On Saturday, 12 March 2016 at 06:07:25 UTC, Mike Parker wrote:
 [...]
I used visual studio 2013 to build the libraries With dflag -m64 and dub flag --arch=x86_64, this happens Running: dub build --arch=x86_64 ## Warning for package rsdlib ## The following compiler flags have been specified in the package description file. They are handled by DUB and direct use in packages is discouraged. Alternatively, you can set the DFLAGS environment variable to pass custom flags to the compiler, or use one of the suggestions below: -m64: Use --arch=x86/--arch=x86_64 to specify the target architecture Performing "debug" build using dmd for x86_64. rsdlib ~master: building configuration "application"... Linking... MSVCRT.lib(MSVCR120.dll) : error LNK2005: exit already defined in LIBCMT.lib(crt0dat.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: free already defined in LIBCMT.lib(free.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: malloc already defined in LIBCMT.lib(malloc.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: __iob_func already defined in LIBCMT.lib(_file.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: fclose already defined in LIBCMT.lib(fclose.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: ferror already defined in LIBCMT.lib(feoferr.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: fflush already defined in LIBCMT.lib(fflush.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: fprintf already defined in LIBCMT.lib(fprintf.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: fread already defined in LIBCMT.lib(fread.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: fwrite already defined in LIBCMT.lib(fwrite.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: ungetc already defined in LIBCMT.lib(ungetc.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: isdigit already defined in LIBCMT.lib(_ctype.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: _fdopen already defined in LIBCMT.lib(fdopen.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: _fileno already defined in LIBCMT.lib(fileno.obj) MSVCRT.lib(MSVCR120.dll) : error LNK2005: _setmode already defined in LIBCMT.lib(setmode.obj) LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library .dub\build\application-debug-windows-x86_64-dmd_2070-F2AB32EEAA78A29A3AA6010 49D38D4A\rsdlib.exe : fatal error LNK1169: one or more multiply defined symbols found --- errorlevel 1169 dmd failed with exit code 1169. and with dflag -m32mscoff, this happens Performing "debug" build using dmd for x86. rsdlib ~master: building configuration "application"... Linking... rsdlib.obj : error LNK2019: unresolved external symbol _BZ2_bzDecompressInit referenced in function _D6rsdlib6cache39Container6decodeFC6rsdlib2io10ByteBufferAiZC6rsdlib6cache39Container rsdlib.obj : error LNK2019: unresolved external symbol _BZ2_bzDecompress referenced in function _D6rsdlib6cache39Container6decodeFC6rsdlib2io10ByteBufferAiZC6rsdlib6cache39Container rsdlib.obj : error LNK2019: unresolved external symbol _BZ2_bzDecompressEnd referenced in function _D6rsdlib6cache39Container6decodeFC6rsdlib2io10ByteBufferAiZC6rsdlib6cache39Container .dub\build\application-debug-windows-x86-dmd_2070-E301E842F2B5FA1A3A9D79D EE34C4E8\rsdlib.exe : fatal error LNK1120: 3 unresolved externals --- errorlevel 1120 dmd failed with exit code 1120.
Mar 11 2016
parent reply Mike Parker <aldacron gmail.com> writes:
On Saturday, 12 March 2016 at 06:50:59 UTC, stunaep wrote:
 On Saturday, 12 March 2016 at 06:07:25 UTC, Mike Parker wrote:
 [...]
I used visual studio 2013 to build the libraries With dflag -m64 and dub flag --arch=x86_64, this happens
You shouldn't specify -m64 in your configuration. DUB will do that for you when you feed it --arch=x86_64.
     LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with 
 use of other libs; use /NODEFAULTLIB:library
     
 .dub\build\application-debug-windows-x86_64-dmd_2070-F2AB32EEAA78A29A3AA6010
49D38D4A\rsdlib.exe : fatal error LNK1169: one or more multiply defined symbols
found
     --- errorlevel 1169
     dmd failed with exit code 1169.
Make sure that DMD's sc.ini is configured to point to the same developer binaries you used to compile the bzip binary. If, for example, it is pointing to, say, an older version of the Windows SDK, but you used VS 2013 Community to compile bzip, conflicts like this are possible. I've had this sort of issue before.
 and with dflag -m32mscoff, this happens

     Performing "debug" build using dmd for x86.
     rsdlib ~master: building configuration "application"...
     Linking...
     rsdlib.obj : error LNK2019: unresolved external symbol 
 _BZ2_bzDecompressInit referenced in function     
 _D6rsdlib6cache39Container6decodeFC6rsdlib2io10ByteBufferAiZC6rsdlib6cache39Container
     rsdlib.obj : error LNK2019: unresolved external symbol 
 _BZ2_bzDecompress referenced in function     
 _D6rsdlib6cache39Container6decodeFC6rsdlib2io10ByteBufferAiZC6rsdlib6cache39Container
     rsdlib.obj : error LNK2019: unresolved external symbol 
 _BZ2_bzDecompressEnd referenced in function     
 _D6rsdlib6cache39Container6decodeFC6rsdlib2io10ByteBufferAiZC6rsdlib6cache39Container
     
 .dub\build\application-debug-windows-x86-dmd_2070-E301E842F2B5FA1A3A9D79D
EE34C4E8\rsdlib.exe : fatal error LNK1120: 3 unresolved externals
     --- errorlevel 1120
     dmd failed with exit code 1120.
DUB does not yet have built-in support for -m32mscoff. Passing it in 'dflags' will cause it to be used to compile your executable, but it will not apply to any dependencies you have. I don't know if this is the cause of these errors or not, but there is an enhancement request in DUB's issue tracker for it [1]. [1] https://github.com/D-Programming-Language/dub/issues/628
Mar 11 2016
next sibling parent stunaep <admin pea2nuts.com> writes:
On Saturday, 12 March 2016 at 07:56:03 UTC, Mike Parker wrote:
 [...]
If I do "dflags" : ["lib/libbzip2.lib"] as Basile B. suggested instead of pragma, I get the same error on x86_64 as I do on x86
Mar 12 2016
prev sibling parent reply stunaep <admin pea2nuts.com> writes:
On Saturday, 12 March 2016 at 07:56:03 UTC, Mike Parker wrote:
  [...]
On Saturday, 12 March 2016 at 09:04:08 UTC, stunaep wrote:
 On Saturday, 12 March 2016 at 07:56:03 UTC, Mike Parker wrote:
 [...]
If I do "dflags" : ["lib/libbzip2.lib"] as Basile B. suggested instead of pragma, I get the same error on x86_64 as I do on x86
I think "dflags" : ["lib/libbzip2.lib"] is not loading anything at all because the same thing happens if I delete the lib file
Mar 12 2016
parent reply Basile B. <b2.temp gmx.com> writes:
On Saturday, 12 March 2016 at 09:53:36 UTC, stunaep wrote:
 On Saturday, 12 March 2016 at 07:56:03 UTC, Mike Parker wrote:
  [...]
On Saturday, 12 March 2016 at 09:04:08 UTC, stunaep wrote:
 On Saturday, 12 March 2016 at 07:56:03 UTC, Mike Parker wrote:
 [...]
If I do "dflags" : ["lib/libbzip2.lib"] as Basile B. suggested instead of pragma, I get the same error on x86_64 as I do on x86
I think "dflags" : ["lib/libbzip2.lib"] is not loading anything at all because the same thing happens if I delete the lib file
"dflags" : ["lib\\libbzip2.lib"] is only if you want to compile as 32 bit AND in OMF, so the -m32mscoff switch must NOT be set (I see that someone else explained you how to compile using the coff object format, which is not the same thing as I've explained before) so in the config you should have something like that "configurations" : [ { "name" : "win32omf", "dflags" : ["lib\\omf32\\libbzip2.lib"] // made with dmc or converted }, { "name" : "win64coff", "dflags" : ["lib\\coff64\\libbzip2.lib", "-m64"] // made with gcc }, ]
Mar 12 2016
parent stunaep <admin pea2nuts.com> writes:
On Saturday, 12 March 2016 at 10:10:44 UTC, Basile B. wrote:
 On Saturday, 12 March 2016 at 09:53:36 UTC, stunaep wrote:
 [...]
"dflags" : ["lib\\libbzip2.lib"] is only if you want to compile as 32 bit AND in OMF, so the -m32mscoff switch must NOT be set (I see that someone else explained you how to compile using the coff object format, which is not the same thing as I've explained before) so in the config you should have something like that "configurations" : [ { "name" : "win32omf", "dflags" : ["lib\\omf32\\libbzip2.lib"] // made with dmc or converted }, { "name" : "win64coff", "dflags" : ["lib\\coff64\\libbzip2.lib", "-m64"] // made with gcc }, ]
Thanks for that. The other issue I had was solved because I wasnt using runtime library /MT when compiling the .lib.
Mar 12 2016
prev sibling parent Basile B. <b2.temp gmx.com> writes:
On Saturday, 12 March 2016 at 05:16:37 UTC, stunaep wrote:
 I'm really having a hard time using bzp (and later I need gzip 
 and lzma).

 So I added this bzip2 D interface to my DUB dependencies
     "dependencies" : {
         "bzip2": "~>0.1.0"
     }

 I downloaded the bzip2 source code and compiled it for windows 
 32bit (will 64 bit work with dmd2?). Then I used coffimplib.exe 
 to convert the .lib file from coff to omf. From there I added 
 this code:
     pragma(lib, "libbzip2OMF.lib");
You can try to compile the bzip2 sources with dmc (http://www.digitalmars.com/download/dmcpp.html) instead of using coffimplib, this will produce directly a static library in OMF format. As for the pragma you can remove it and add this to your JSON: "dflags": ["bin\bz2.lib"], for example if the lib is located in the "bin" subfolder and named "bz2.lib"
Mar 11 2016