URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [zlib/] [win32/] [DLL_FAQ.txt] - Rev 745
Compare with Previous | Blame | View Log
Frequently Asked Questions about ZLIB1.DLLThis document describes the design, the rationale, and the usageof the official DLL build of zlib, named ZLIB1.DLL. If you havegeneral questions about zlib, you should see the file "FAQ" foundin the zlib distribution, or at the following location:http://www.gzip.org/zlib/zlib_faq.html1. What is ZLIB1.DLL, and how can I get it?- ZLIB1.DLL is the official build of zlib as a DLL.(Please remark the character '1' in the name.)Pointers to a precompiled ZLIB1.DLL can be found in the zlibweb site at:http://www.zlib.org/Applications that link to ZLIB1.DLL can rely on the followingspecification:* The exported symbols are exclusively defined in the sourcefiles "zlib.h" and "zlib.def", found in an official zlibsource distribution.* The symbols are exported by name, not by ordinal.* The exported names are undecorated.* The calling convention of functions is "C" (CDECL).* The ZLIB1.DLL binary is linked to MSVCRT.DLL.The archive in which ZLIB1.DLL is bundled contains compiledtest programs that must run with a valid build of ZLIB1.DLL.It is recommended to download the prebuilt DLL from the zlibweb site, instead of building it yourself, to avoid potentialincompatibilities that could be introduced by your compilerand build settings. If you do build the DLL yourself, pleasemake sure that it complies with all the above requirements,and it runs with the precompiled test programs, bundled withthe original ZLIB1.DLL distribution.If, for any reason, you need to build an incompatible DLL,please use a different file name.2. Why did you change the name of the DLL to ZLIB1.DLL?What happened to the old ZLIB.DLL?- The old ZLIB.DLL, built from zlib-1.1.4 or earlier, requiredcompilation settings that were incompatible to those used bya static build. The DLL settings were supposed to be enabledby defining the macro ZLIB_DLL, before including "zlib.h".Incorrect handling of this macro was silently accepted atbuild time, resulting in two major problems:* ZLIB_DLL was missing from the old makefile. When buildingthe DLL, not all people added it to the build options. Inconsequence, incompatible incarnations of ZLIB.DLL startedto circulate around the net.* When switching from using the static library to using theDLL, applications had to define the ZLIB_DLL macro andto recompile all the sources that contained calls to zlibfunctions. Failure to do so resulted in creating binariesthat were unable to run with the official ZLIB.DLL build.The only possible solution that we could foresee was to makea binary-incompatible change in the DLL interface, in order toremove the dependency on the ZLIB_DLL macro, and to releasethe new DLL under a different name.We chose the name ZLIB1.DLL, where '1' indicates the majorzlib version number. We hope that we will not have to breakthe binary compatibility again, at least not as long as thezlib-1.x series will last.There is still a ZLIB_DLL macro, that can trigger a moreefficient build and use of the DLL, but compatibility nolonger dependents on it.3. Can I build ZLIB.DLL from the new zlib sources, and replacean old ZLIB.DLL, that was built from zlib-1.1.4 or earlier?- In principle, you can do it by assigning calling conventionkeywords to the macros ZEXPORT and ZEXPORTVA. In practice,it depends on what you mean by "an old ZLIB.DLL", because theold DLL exists in several mutually-incompatible versions.You have to find out first what kind of calling convention isbeing used in your particular ZLIB.DLL build, and to use thesame one in the new build. If you don't know what this is allabout, you might be better off if you would just leave the oldDLL intact.4. Can I compile my application using the new zlib interface, andlink it to an old ZLIB.DLL, that was built from zlib-1.1.4 orearlier?- The official answer is "no"; the real answer depends again onwhat kind of ZLIB.DLL you have. Even if you are lucky, thiscourse of action is unreliable.If you rebuild your application and you intend to use a newerversion of zlib (post- 1.1.4), it is strongly recommended tolink it to the new ZLIB1.DLL.5. Why are the zlib symbols exported by name, and not by ordinal?- Although exporting symbols by ordinal is a little faster, itis risky. Any single glitch in the maintenance or use of theDEF file that contains the ordinals can result in incompatiblebuilds and frustrating crashes. Simply put, the benefits ofexporting symbols by ordinal do not justify the risks.Technically, it should be possible to maintain ordinals inthe DEF file, and still export the symbols by name. Ordinalsexist in every DLL, and even if the dynamic linking performedat the DLL startup is searching for names, ordinals serve ashints, for a faster name lookup. However, if the DEF filecontains ordinals, the Microsoft linker automatically buildsan implib that will cause the executables linked to it to usethose ordinals, and not the names. It is interesting tonotice that the GNU linker for Win32 does not suffer from thisproblem.It is possible to avoid the DEF file if the exported symbolsare accompanied by a "__declspec(dllexport)" attribute in thesource files. You can do this in zlib by predefining theZLIB_DLL macro.6. I see that the ZLIB1.DLL functions use the "C" (CDECL) callingconvention. Why not use the STDCALL convention?STDCALL is the standard convention in Win32, and I need it inmy Visual Basic project!(For readability, we use CDECL to refer to the conventiontriggered by the "__cdecl" keyword, STDCALL to refer tothe convention triggered by "__stdcall", and FASTCALL torefer to the convention triggered by "__fastcall".)- Most of the native Windows API functions (without varargs) useindeed the WINAPI convention (which translates to STDCALL inWin32), but the standard C functions use CDECL. If a userapplication is intrinsically tied to the Windows API (e.g.it calls native Windows API functions such as CreateFile()),sometimes it makes sense to decorate its own functions withWINAPI. But if ANSI C or POSIX portability is a goal (e.g.it calls standard C functions such as fopen()), it is not asound decision to request the inclusion of <windows.h>, or touse non-ANSI constructs, for the sole purpose to make the userfunctions STDCALL-able.The functionality offered by zlib is not in the category of"Windows functionality", but is more like "C functionality".Technically, STDCALL is not bad; in fact, it is slightlyfaster than CDECL, and it works with variable-argumentfunctions, just like CDECL. It is unfortunate that, in spiteof using STDCALL in the Windows API, it is not the defaultconvention used by the C compilers that run under Windows.The roots of the problem reside deep inside the unsafety ofthe K&R-style function prototypes, where the argument typesare not specified; but that is another story for another day.The remaining fact is that CDECL is the default convention.Even if an explicit convention is hard-coded into the functionprototypes inside C headers, problems may appear. Thenecessity to expose the convention in users' callbacks is oneof these problems.The calling convention issues are also important when usingzlib in other programming languages. Some of them, like Ada(GNAT) and Fortran (GNU G77), have C bindings implementedinitially on Unix, and relying on the C calling convention.On the other hand, the pre- .NET versions of Microsoft VisualBasic require STDCALL, while Borland Delphi prefers, althoughit does not require, FASTCALL.In fairness to all possible uses of zlib outside the Cprogramming language, we choose the default "C" convention.Anyone interested in different bindings or conventions isencouraged to maintain specialized projects. The "contrib/"directory from the zlib distribution already holds a coupleof foreign bindings, such as Ada, C++, and Delphi.7. I need a DLL for my Visual Basic project. What can I do?- Define the ZLIB_WINAPI macro before including "zlib.h", whenbuilding both the DLL and the user application (except thatyou don't need to define anything when using the DLL in VisualBasic). The ZLIB_WINAPI macro will switch on the WINAPI(STDCALL) convention. The name of this DLL must be differentthan the official ZLIB1.DLL.Gilles Vollant has contributed a build named ZLIBWAPI.DLL,with the ZLIB_WINAPI macro turned on, and with the minizipfunctionality built in. For more information, please readthe notes inside "contrib/vstudio/readme.txt", found in thezlib distribution.8. I need to use zlib in my Microsoft .NET project. What can Ido?- Henrik Ravn has contributed a .NET wrapper around zlib. Lookinto contrib/dotzlib/, inside the zlib distribution.9. If my application uses ZLIB1.DLL, should I link it toMSVCRT.DLL? Why?- It is not required, but it is recommended to link yourapplication to MSVCRT.DLL, if it uses ZLIB1.DLL.The executables (.EXE, .DLL, etc.) that are involved in thesame process and are using the C run-time library (i.e. theyare calling standard C functions), must link to the samelibrary. There are several libraries in the Win32 system:CRTDLL.DLL, MSVCRT.DLL, the static C libraries, etc.Since ZLIB1.DLL is linked to MSVCRT.DLL, the executables thatdepend on it should also be linked to MSVCRT.DLL.10. Why are you saying that ZLIB1.DLL and my application shouldbe linked to the same C run-time (CRT) library? I linked myapplication and my DLLs to different C libraries (e.g. myapplication to a static library, and my DLLs to MSVCRT.DLL),and everything works fine.- If a user library invokes only pure Win32 API (accessible via<windows.h> and the related headers), its DLL build will workin any context. But if this library invokes standard C API,things get more complicated.There is a single Win32 library in a Win32 system. Everyfunction in this library resides in a single DLL module, thatis safe to call from anywhere. On the other hand, there aremultiple versions of the C library, and each of them has itsown separate internal state. Standalone executables and userDLLs that call standard C functions must link to a C run-time(CRT) library, be it static or shared (DLL). Intermixingoccurs when an executable (not necessarily standalone) and aDLL are linked to different CRTs, and both are running in thesame process.Intermixing multiple CRTs is possible, as long as theirinternal states are kept intact. The Microsoft Knowledge Basearticles KB94248 "HOWTO: Use the C Run-Time" and KB140584"HOWTO: Link with the Correct C Run-Time (CRT) Library"mention the potential problems raised by intermixing.If intermixing works for you, it's because your applicationand DLLs are avoiding the corruption of each of the CRTs'internal states, maybe by careful design, or maybe by fortune.Also note that linking ZLIB1.DLL to non-Microsoft CRTs, suchas those provided by Borland, raises similar problems.11. Why are you linking ZLIB1.DLL to MSVCRT.DLL?- MSVCRT.DLL exists on every Windows 95 with a new service packinstalled, or with Microsoft Internet Explorer 4 or later, andon all other Windows 4.x or later (Windows 98, Windows NT 4,or later). It is freely distributable; if not present in thesystem, it can be downloaded from Microsoft or from othersoftware provider for free.The fact that MSVCRT.DLL does not exist on a virgin Windows 95is not so problematic. Windows 95 is scarcely found nowadays,Microsoft ended its support a long time ago, and many recentapplications from various vendors, including Microsoft, do noteven run on it. Furthermore, no serious user should runWindows 95 without a proper update installed.12. Why are you not linking ZLIB1.DLL to<<my favorite C run-time library>> ?- We considered and abandoned the following alternatives:* Linking ZLIB1.DLL to a static C library (LIBC.LIB, orLIBCMT.LIB) is not a good option. People are using the DLLmainly to save disk space. If you are linking your programto a static C library, you may as well consider linking zlibin statically, too.* Linking ZLIB1.DLL to CRTDLL.DLL looks appealing, becauseCRTDLL.DLL is present on every Win32 installation.Unfortunately, it has a series of problems: it does notwork properly with Microsoft's C++ libraries, it does notprovide support for 64-bit file offsets, (and so on...),and Microsoft discontinued its support a long time ago.* Linking ZLIB1.DLL to MSVCR70.DLL or MSVCR71.DLL, suppliedwith the Microsoft .NET platform, and Visual C++ 7.0/7.1,raises problems related to the status of ZLIB1.DLL as asystem component. According to the Microsoft Knowledge Basearticle KB326922 "INFO: Redistribution of the Shared CRuntime Component in Visual C++ .NET", MSVCR70.DLL andMSVCR71.DLL are not supposed to function as system DLLs,because they may clash with MSVCRT.DLL. Instead, theapplication's installer is supposed to put these DLLs(if needed) in the application's private directory.If ZLIB1.DLL depends on a non-system runtime, it cannotfunction as a redistributable system component.* Linking ZLIB1.DLL to non-Microsoft runtimes, such asBorland's, or Cygwin's, raises problems related to thereliable presence of these runtimes on Win32 systems.It's easier to let the DLL build of zlib up to the peoplewho distribute these runtimes, and who may proceed asexplained in the answer to Question 14.13. If ZLIB1.DLL cannot be linked to MSVCR70.DLL or MSVCR71.DLL,how can I build/use ZLIB1.DLL in Microsoft Visual C++ 7.0(Visual Studio .NET) or newer?- Due to the problems explained in the Microsoft Knowledge Basearticle KB326922 (see the previous answer), the C runtime thatcomes with the VC7 environment is no longer considered asystem component. That is, it should not be assumed that thisruntime exists, or may be installed in a system directory.Since ZLIB1.DLL is supposed to be a system component, it maynot depend on a non-system component.In order to link ZLIB1.DLL and your application to MSVCRT.DLLin VC7, you need the library of Visual C++ 6.0 or older. Ifyou don't have this library at hand, it's probably best not touse ZLIB1.DLL.We are hoping that, in the future, Microsoft will provide away to build applications linked to a proper system runtime,from the Visual C++ environment. Until then, you have acouple of alternatives, such as linking zlib in statically.If your application requires dynamic linking, you may proceedas explained in the answer to Question 14.14. I need to link my own DLL build to a CRT different thanMSVCRT.DLL. What can I do?- Feel free to rebuild the DLL from the zlib sources, and linkit the way you want. You should, however, clearly state thatyour build is unofficial. You should give it a different filename, and/or install it in a private directory that can beaccessed by your application only, and is not visible to theothers (e.g. it's not in the SYSTEM or the SYSTEM32 directory,and it's not in the PATH). Otherwise, your build may clashwith applications that link to the official build.For example, in Cygwin, zlib is linked to the Cygwin runtimeCYGWIN1.DLL, and it is distributed under the name CYGZ.DLL.15. May I include additional pieces of code that I find useful,link them in ZLIB1.DLL, and export them?- No. A legitimate build of ZLIB1.DLL must not include codethat does not originate from the official zlib source code.But you can make your own private DLL build, under a differentfile name, as suggested in the previous answer.For example, zlib is a part of the VCL library, distributedwith Borland Delphi and C++ Builder. The DLL build of VCLis a redistributable file, named VCLxx.DLL.16. May I remove some functionality out of ZLIB1.DLL, by enablingmacros like NO_GZCOMPRESS or NO_GZIP at compile time?- No. A legitimate build of ZLIB1.DLL must provide the completezlib functionality, as implemented in the official zlib sourcecode. But you can make your own private DLL build, under adifferent file name, as suggested in the previous answer.17. I made my own ZLIB1.DLL build. Can I test it for compliance?- We prefer that you download the official DLL from the zlibweb site. If you need something peculiar from this DLL, youcan send your suggestion to the zlib mailing list.However, in case you do rebuild the DLL yourself, you can runit with the test programs found in the DLL distribution.Running these test programs is not a guarantee of compliance,but a failure can imply a detected problem.**This document is written and maintained byCosmin Truta <cosmint@cs.ubbcluj.ro>
