关于electron:开发Electron不小心接触到C经过一周多的时间终于摸索出

26次阅读

共计 2662 个字符,预计需要花费 7 分钟才能阅读完成。

为啥要写二进制编译 exe 程序,CMake minGW 练习教程?

前阵子,钻研了一下 electron, 想开发一款离线图片压缩桌面程序。写的过程中发现程序在,windows 环境下运行没问题,然而在 linux 和 macOS 会有问题。常常排查发现是 node 依赖的第三方插件问题(只给了 exe 程序)。
所以开始着手钻研,如何通过 c++ 之类的源码,编译出别离对应 Wndows Linux MacOS 的二进制应用程序。
通过一周的工夫查阅大量的材料(google),最终得出上面的流程。

当初只是学会了,编译 Linux 和 windows 的应用程序,然而我想要是 在一个零碎环境下别离编译出 Windows Linux MacOS。目前只接触到了 穿插编译 这个货色。正在着手学习,摸索出残缺无坑的流程再持续发相干文章。

本文存储于 github

工具筹备

OS:windows 10

CMake: https://cmake.org/

Visual Studio 2019: https://visualstudio.microsof…

下载 libpng-1.6.35 源码 Download the libpng-1.6.35 source code

libpng: https://github.com/glennrp/li…

解压 libpng-1.6.35.tar.gz

directory
|-libpng-1.6.35

关上 zlib.props 文件,查看依赖 zlib 的版本

libpng > projects -> vstudio -> zlib.props

line 34  <ZLibSrcDir>..\..\..\..\zlib-1.2.8</ZLibSrcDir>

下载 zlib-1.2.8 源码 Download the zlib-1.2.8 source code

zlib : https://github.com/madler/zli…

解压 zlib-1.2.8.tar.gz

directory
|-libpng-1.6.35
|-zlib-1.2.8

编译 zlib-1.2.8

  1. 关上 CMake gui
  2. 点击 Browse Source 抉择 zlib-1.2.8

  1. 点击 Browse Build 抉择 zlib-1.2.8/build 目录
  2. 点击 Configure(生成 CMake Cahce) 抉择 Visual Studio
  3. 和 x64 点击 Finish 期待输入音讯 Configuring done

  1. 点击 Generate(生成 Visual Studio 的 *.sln) 期待输入音讯 Generating done

  1. 点击 Open Project,会在 Visual Studio
  2. 中关上
  3. 生成 debug 版的动态链接库。

    (1). 确认解决方案为 debug、X64 平台。(2). 在 zlibstatic 我的项目上右击–> 生成  期待 输入窗口提醒生成胜利 (2 个)
    
    (3). zlib 的 debug、X64 版的动态链接库曾经编译胜利。![5.png](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/3280b06039684e1da05855fdd2c762c4~tplv-k3u1fbpfcp-watermark.image)
  4. 生成 release 版的动态链接库。

    (1). 确认解决方案为 release、X64 平台。(2). 在 zlibstatic 我的项目上右击–> 生成  期待 输入窗口提醒生成胜利 (2 个)
    
    (3). zlib 的 release、X64 版的动态链接库曾经编译胜利。

  1. 最重要的一步 复制 zlib-1.2.8/build/zconf.h 文件到 zlib-1.2.8/

编译 libpng-1.6.35

  1. 关上 CMake gui
  2. 点击 Browse Source 抉择 zlib-1.2.8
  3. 点击 Browse Build 抉择 zlib-1.2.8/build 目录
  4. 勾选 Advanced, 批改 ZLIB_INCLUDE_DIR,ZLIB_LIBRARY_DEBUG、ZLIB_LIBRARY_RELEASE 后点击 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.lib

  5. 单击 Generate,生成 Visual Studio 2019 的 *.sln 我的项目。
  6. 点击 Open Project,会在 Visual Studio 2019 中关上
  7. 在 Visual Studio 2019 中别离以 Debug 和 Release 形式编译 png_static 我的项目。

编译 mozjpeg-4.0.3

没有前置依赖 按下面的流程即可

我想用 minGW 怎么编译?

  1. 在 CMake gui 中,点击 Configure,抉择“MinGW Makefile”期待 Configuring done
  2. 点击 Generate 期待 Generate done
  3. 关上 cmd, 执行命令 cd C:\c++\zlib-1.2.8\build\
  4. 执行 minGW32-make (每个装置的 minGW make 命令可能不一样 自行抉择即可)

编译进去的 exe 我独自复制进去不能怎么回事?

因为 应用程序 须要依赖 某个 dll,将这个 dll 放在和 exe 程序同一地位即可

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.

正文完
 0