Compile libharu based on Visual Studio under Windows

Because the project needs pdf output and can control the size well, Li libharu is chosen.

The source code is all on the Internet, and you need to compile it yourself. After referring to many articles, it was unsuccessful in the end. Finally, it was found that it was the reason for compiling zlib and libpng. In fact, the key point is the modification of the preprocessing macro ZLIB_WINAPI.

You can refer to:

Window compiles libharu and dependent libraries zlib and libpng

Compilation and use of zlib library and libPng library under Windows

But I still don't feel that the compilation problem of libharu is clear.

From the perspective of use, libharu can be compiled in two ways, one is a static library and the other is a dynamic library. The static library will not be discussed for the time being. Mainly talk about the way of dynamic library.

For the dynamic library, since it depends on the two libraries, zlib and libpng, there are two kinds of compilation of the dynamic library:

  1. libharu, zlib, and libpng are all compiled into dynamic libraries. When using, these three dll files must be imported in order to run successfully.
  2. zlib and libpng are compiled into static libraries. When compiling libharu, these contents are compiled into libharu.dll. In this way, when the project is referenced, only the compiled libharu.dll needs to be imported, and the dependent zlib and libpng dlls are no need.

Method 1 is generally used on the Internet. So here is the compilation of method two.

First get the static libraries of zlib and libpng:

  1. Compile the static library of zlib and open the corresponding vs version sln in the zlib\contrib\vstudio directory. The zlibstat project is used to compile the static library. Note that it is set to: zlib_winapi in the definition of the preprocessor, and the runtime library for code generation is selected as /MD.
  2. Compile the libpng static library and open libpng.sln in the libpng\projects\visualc71 directory. Among them, the lib release mode is to output a static library. Note: it is consistent with zlib in the preprocessing definition; the thread library selection is /MD; the most important thing is the dependent zlib library, it is best to choose the zlib library compiled in the first step , instead of compiling with the zlib project configured in the project.

In this way, two files, zlib.lib and libpng.lib, are obtained.

Then compile libharu

  1. Rely on zlib.lib and libpng.lib when compiling, set the lib storage location and the corresponding h header file location, and then modify the Makefile.msvc_dll file in the script directory: PNG_PREFIX and ZLIB_PREFIX, so that when compiling, you can find The corresponding lib and h files.
  2. Add CFLAGS macro definition, consistent with zlib: /D "ZLIB_WINAPI" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_WARNINGS" /D "ASMV" /D "ASMIF"
  3. Modify libpng13.dll in LDFLAGS to libpng.dll
  4. Enter the command prompt console of vs, enter the libharu directory, and execute nmake -f script/Makefile.msvc_dll to get libharu.dll containing zlib and libpng codes

In this way, when using libharu, only one libpng.dll is needed, and there is no need to attach two dll files, zlib and libpng.

It should be noted that the static library generates lib files, and the dynamic library also generates lib files. The suffixes of these two lib files are the same, but the content is different. The specific difference is the difference between Baidu static library and dynamic library.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326009333&siteId=291194637
Recommended