CMake minGW 教程 CMake minGW 教程

Some time ago, I studied electron and wanted to develop an offline image compression desktop program. As I was writing it, I realized that it would work fine on Windows, but it would have problems on Linux and macOS. Check frequently to find that node depends on the third party plug-in problem (only to exe program). So I began to study how to compile binary applications corresponding to Wndows Linux MacOS through c++ source code. After a week of looking through a lot of data (Google), I finally came up with the following process.

Now I’ve just learned how to compile Linux and Windows applications, but I want to compile Windows Linux MacOS separately on one system. So far we’ve only touched on cross-compilation. I am learning, and I will continue to post relevant articles after I find out the complete pit free process.

This article is hosted on Github

Tools to prepare

OS: windows 10

CMake: cmake.org/

Visual Studio 2019: visualstudio.microsoft.com/zh-hans/

Download the libpng-1.6.35 source code

Libpng: github.com/glennrp/lib…

Unpack the libpng – 1.6.35. Tar. Gz

The directory | - libpng - 1.6.35Copy the code

Open the zlib.props file to see the zlib-dependent versions

libpng > projects -> vstudio -> zlib.props

line 34 <ZLibSrcDir>.. \.. \.. \.. \ zlib - 1.2.8 < / ZLibSrcDir >Copy the code

Download the zlib-1.2.8 source code from zlib-1.2.8

Zlib: github.com/madler/zlib…

Unpack the zlib – 1.2.8. Tar. Gz

The directory | - libpng - 1.6.35 | - zlib - 1.2.8Copy the code

Compile zlib – 1.2.8

  1. Open the CMake GUI

  1. Click Browse Source to select Zlib-1.2.8

3. Click Browse Build to select the zlib-1.2.8/ Build directory

  1. Click Configure to select Visual Studio

Click Finish to output the message Configuring Done for 2019 and X64

5. Click Generate to Generate *.sln for Visual Studio and wait for output message Generating done

6. Click Open Project and it will Open in Visual Studio 2019

  1. Build a debug version of the static link library.

    (1). Ensure that the solution is DEBUG or X64 platform.

    (2). Right click on the Zlibstatic project – > Build and wait for the output window to indicate that the build succeeded (2)

    (3). The debug of Zlib and the static link library of X64 have been compiled successfully.

  2. Build a release static link library.

    (1). Confirm that the solution is Release and X64 platform.

    (2). Right click on the Zlibstatic project – > Build and wait for the output window to indicate that the build succeeded (2)

    (3). Zlib release and X64 static link library have been compiled successfully.

  1. The most important step is to copy the zlib-1.2.8/build/zconf.h file to zlib-1.2.8/

Compile the libpng – 1.6.35

  1. Open the CMake GUI

  2. Click Browse Source to select Zlib-1.2.8

  3. Click Browse Build to select the zlib-1.2.8/ Build directory

  4. Select Advanced, modify ZLIB_INCLUDE_DIR,ZLIB_LIBRARY_DEBUG, ZLIB_LIBRARY_RELEASE and click Configure

    ZLIB_INCLUDE_DIR C:\ C ++\zlib-1.2.8 ZLIB_LIBRARY_DEBUG C:\ C ++\zlib-1.2.8\build\Debug\zlibstatic.lib ZLIB_LIBRARY_RELEASE C: \ \ C + + zlib - 1.2.8 / build/Release \ zlibstatic libCopy the code

  5. Click Generate to Generate the *.sln project for Visual Studio 2019.

  6. Click Open Project and it will Open in Visual Studio 2019

  7. Compile pNG_static projects with Debug and Release respectively in Visual Studio 2019.

Compile mozjpeg – 4.0.3

Follow the above procedure if there are no front dependencies

How do I want to compile with minGW?

  1. In the CMake GUI, click Configure and select “MinGW Makefile” to wait for Configuring Done
  2. Click Generate and wait for Generate done
  3. Open CMD and run the commandCD C: \ \ zlib - 1.2.8 \ build \ C + +
  4. Execute the mingw32-make command (each installation may have different minGW make commands).

I can’t copy the compiled exe separately.

Because the application needs to rely on a DLL, put the DLL in the same place as the EXE program

Built on

  • Github
  • libpng: libpng is the official PNG reference library.
  • zlib: ZLIB DATA COMPRESSION LIBRARY
  • mozjpeg: MozJPEG improves JPEG compression efficiency achieving higher visual quality and smaller file sizes at the same time.
  • CMake: CMake is an open-source, cross-platform family of tools designed to build, test and package software.
  • Visual Studio 2019:A full-featured IDE that can be used to code, debug, test, and deploy to any platform.
  • minGw:Mingw-w64 is an advancement of the original mingw.org project, created to support the GCC compiler on Windows systems.