Compilation and use of zlib libraries and libpng libraries under windows

Source: Internet
Author: User

About Zlib Library and libpng is what, I don't say, degrees Niang and Google can tell you. Here is a main note on how to compile and use the two libraries under Windows using VS2010.

First, the compilation of Zlib library

First of all to download this library, this Google and Baidu can also be found. I downloaded the zlib-1.2.5, downloaded after the decompression can be. Let's start compiling below. (including both dynamic and static libraries)

1. First open the command Prompt (32bit) of VS2010, which is the commands prompt window.

2. Go to the Zlib-1.2.5/contrib/masmx86 directory and execute bld_ml32.bat. (Similarly, a 64-bit computer enters the masmx64 directory and executes Bld_ml64.bat). This step runs the bld_ml32 batch file, which calls the ML command to compile inffas32.asm and match686.asm, generating inffas32.obj and match686.obj (generated in this directory). These two files are used in ZLIBVC.

3. The Zlib vs SLN solution file can be found in the following path: ZLIB-1.2.5/CONTRIB/VSTUDIO/VC10/ZLIBVC.sln, open

The solution consists of 6 projects. which

(1). ZLIBVC generate the dynamic link library zlibwapi.dll and the corresponding import library Zlibwapi.lib

( 2 ). Zlibstat generate a static link library zlibstat.lib

(3 ). Testzlibdll test-generated dynamic-link library zlibwapi.dll

(4). Testzlib test generated static link library zlibstat.lib        

Finally we compile the entire solution in debug mode. The generated DLLs and Lib files can be found in the appropriate folder.

The below describes how to use compiled dynamic or static libraries. (assuming project engineering has been established)

Here we put the static library zlibstat.lib and the Dynamic Library (zlibwapi.dll/zlibwapi.lib) and the Zlib.h/zlibconf.h file in a folder.

second, use zlib static library: Zlibstat.lib

1. Include Header files
Property--c/c++--General--Additional Include directories (add a directory containing. h files)
2. Defining macros
Property--c/c++--Preprocessor-Preprocessor definition: Add zlib_winapi ASMV asminf
3. The project contains the directory where the. lib file is located:
Properties--linker--general--additional Library Directory
4. Project contains. lib Files
Properties--linker--input--Additional dependencies ( libstat.lib)

5. #include "Zlib.h" in the project code
Compiled build. exe is ready to use.

third, the use of dynamic library Zlibwapi.lib1. Include Header files
Property--c/c++--General--Additional Include directories (add a directory containing. h)
2. Defining macros
Property--c/c++--Preprocessor-preprocessor definition: Adding ZLIB_WINAPI
3. The project contains the directory where the. lib file is located:
Properties--linker--general--additional Library Directory
4. Project contains. lib Files
Properties - -linker--input--Additional dependencies (zlibwapi.lib)

5. #include "Zlib.h" in the project code
A. dll file is required for compiling build. exe files (dynamic loading)

iv. Compilation of Libpng

1. First to download this library, I downloaded the libpng-1.2.37, unzip.

2. This solution opens the Libpng.sln in libpng-1.2.37/projects/visualc71. Open with VS2010 may require conversion, click Next to convert.

3. Don't rush to compile. First Analyze This solution:

The Libpng project for this solution is by default the dynamic library (. dll) compiled (properties--Configuration Properties--general--Project default type ). We can compile the static library directly, generate the. dll file and the. lib file. At compile time, may error, anyway is a variety of errors, not missing this is missing that, very annoying, here I would like to compile static type, so there is no research on this. below to static type compilation, here is a bit of trouble, don't worry.

4. Static compilation requires a macro definition, we first open the project properties--Configuration Properties--c/c++--Preprocessor definitions, here we see some macros defined at dynamic compile time. Here are two useful for us: Png_build_dll and Zlib_dll.

5. Find Png_build_dll throughout the solution, We can see the following code in the Pngconf.h file:

normal" Png-on-win32 defines/defaults:
PNG_ build_dll --Building DLL
png_use_dll     --building an application, linking to DLL
(no define)      --building Static library, or building an
                                 application and linking to the static Lib

It is obvious here that if we need to compile a static library, we need no define. So we delete the Png_build_dll macro definition.

6. Looking for zlib_dll throughout the solution, we will find the following sentence:

If building or using zlib as a DLL, define Zlib_dll

This is just to tell us that if we use zlib as a DLL, we define Zlib_dll. But we do not want to do this here, so continue to analyze. There are a few words below:

If building or using zlib with the WINAPI/WINAPIV calling convention,
Define ZLIB_WINAPI.
Caution:the Standard ZLIB1. DLLs are not compiled using ZLIB_WINAPI.

This paragraph of English is not particularly understand, but can know, we define ZLIB_WINAPI can. This is also used in the compilation of the zlib static library above, so it should be defined as such. We delete zlib_dll in the preprocessor definition and change to ZLIB_WINAPI.

7. When the macro is defined, the most critical step is to change to the static library (. lib) in the properties--configuration Properties--general--Project default type. The compile option is changed to Lib Debug. Compile the build. The resulting file is libpngd.lib.

The below describes how to use a compiled static library. (assuming project engineering has been established)

Here we put the static library Libpngd.lib and png.h/pngconf.h files in a folder.

v. Use of libpng Static library (libpngd.lib).

1. Include Header files
Property--c/c++--General--Additional Include directories (add a directory containing. h files)
2. Defining macros
This is because the zlib library is used, so as long as you define Zlib_winapi

3. The project contains the directory where the. lib file is located:
Properties--linker--general--additional Library Directory
4. Project contains. lib Files
Properties--linker--input--Additional dependencies ( libpngd.lib)

5. #include "Png.h" in the project code
Compiled build. exe is ready to use.

Note: At compile time, the following warning may appear:

Warning LNK4099: PDB "vc100.pdb" (...) not found The object is being linked as if there is no debug information

This does not affect the operation of the code.



Reference:http://blog.sina.com.cn/s/blog_74dfa9f40101h33m.htmlZlib and libpng download: http://olex.openlogic.com/packages/zlib/1.2.5 http://sourceforge.net/projects/libpng/f iles/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.