Compilation and use of zlib libraries and libpng libraries under windows

Source: Internet
Author: User

What about the Zlib library and libpng? I'm not going to say it. Mom and Google can tell you. Here's 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 download is zlib-1.2.5, download the decompression out can.

Start compiling below.

(includes both dynamic and static libraries)

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

2. Go to the Zlib-1.2.5/contrib/masmx86 folder. Run Bld_ml32.bat.

Empathy 64-bit PC into the Masmx64 folder, run Bld_ml64.bat). This step runs the bld_ml32 batch file, which calls the ML command to compile inffas32.asm and match686.asm. Generate Inffas32.obj and match686.obj (generated under this folder). These two files are used in ZLIBVC.

3. The Zlib vs SLN solution file can be found in the following path, for example: ZLIB-1.2.5/CONTRIB/VSTUDIO/VC10/ZLIBV C.sln. Open it

This workaround includes 6 project.

Of

(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 corresponding directory.

The below describes how to use compiled dynamic or static libraries. (if Project is already completed)

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 directory.

second, use zlib static library: Zlibstat.lib

1. Include Header files
Property--c/c++--General--Attach Include folder (add folder including. h file)
2. Defining macros
attribute--c/c++--preprocessor-preprocessor definition: Join ZLIB_WINAPI ASMV asminf
3. The project includes the folder where the. lib file is located:
Properties--linker--general--Attach Library folder
4. The project includes the. lib file
Properties--linker--input--Additional dependencies ( libstat.lib)

5. #include "Zlib.h" in the project code
Compiling a build. exe is available.

third, the use of dynamic library Zlibwapi.lib1. Include Header files
Property--c/c++--General--Attach Include folder (add folder including. h)
2. Defining macros
attribute--c/c++--preprocessor-preprocessor definition: Join ZLIB_WINAPI
3. The project includes the folder where the. lib file is located:
Properties--linker--general--Attach Library folder
4. The project includes the. lib file
Properties - -linker--input--Additional dependencies (zlibwapi.lib)

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

iv. Compilation of Libpng

1. To download this library first, I downloaded the libpng-1.2.37. Extract.

2. This solution is in libpng-1.2.37/projects/visualc71, open Libpng.sln. Open with vs2010 may need to be converted, click Next to convert it.

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

The Libpng project for this workaround is by default the built-in dynamic library (. dll) compiled (properties--Configuration Properties--general--Project default type ). We are able to compile static libraries directly. Generate. dll files and. lib files.

At compile time, may error, anyway is a variety of errors, not missing this is missing that, very annoying. I was trying to compile a static type here, so I'm not studying this.

It's a bit of a hassle to change the bottom to static type compilation. 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 to 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 very 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 telling us. Suppose we use the zlib as a DLL. The zlib_dll is defined. 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 as you like.

The resulting file is libpngd.lib.

The below describes how to use a compiled static library.

(if Project is already completed)

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

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

1. Include Header files
Property--c/c++--General--Attach Include folder (add folder including. h file)
2. Defining macros
This is due to the use of the zlib library, so just define Zlib_winapi to

3. The project includes the folder where the. lib file is located:
Properties--linker--general--Attach Library folder
4. The project includes the. lib file
Properties--linker--input--Additional dependencies ( libpngd.lib)

5. #include "Png.h" in the project code
Compiling a build. exe is available.

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

Warning LNK4099: PDB "vc100.pdb" (...) not found ; The object is being linked. As without debugging information

This does not affect the execution of the code.



References: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/

Compilation and use of zlib libraries and libpng libraries under windows

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.