2

在 Windows msys2 下编译 scryer-prolog - chesium

 1 year ago
source link: https://www.cnblogs.com/chesium/p/16516034.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在 Windows msys2 下编译 scryer-prolog

by chesium 2022/7/24 深夜

参考:https://github.com/mthom/scryer-prolog/blob/master/README.md

采用 msys2 环境编译

On Windows, Scryer Prolog is easier to build inside a msys2 environment as some crates may require native C compilation. However, the resulting binary does not need msys2 to run. When executing Scryer in a shell, it is recommended to use a more advanced shell than mintty (the default msys2 shell). The Windows Terminal works correctly.

  1. 下载msys2官网,并安装
    • 安装耗时较长
    • 不要安装在C:\Program Files等路径包含空格的位置,不然后续编译中会报错。
    • (可选)配置Windows Terminal终端:(最好加上管理员权限,如采用 gsudo
    <...>\msys2_shell.cmd -defterm -no-start
  2. 给 msys2 安装diffutilsm4,不然后续编译会报错:
    pacman -S diffutilspacman -S m4
  3. 安装 Rust(到 Windows 系统中即可),参照官网(安装时选2) Customize installation,将默认为x86_64-pc-windows-msvc的基础编译工具更换为x86_64-pc-windows-gnu,其他选项采用默认。参考),并添加到 msys2 的环境变量中:
    export PATH=$PATH:/c/Users/<用户名>/.cargo/bin
  4. 同样的,将 Windows 下gcc.exe所在的文件夹也添加到 msys2 的环境变量中,(不然后续编译会报错)格式见上。若未安装,可自行查找安装教程。
  5. 克隆代码库:https://github.com/mthom/scryer-prolog.git至任意文件夹(最好到msys2的home/<username>文件夹里),将 msys2 终端cd到该目录中。
  6. 编译:在 msys2 终端中执行 cargo run --release,如果嫌输出信息太少感觉卡住了可以加上-vv选项
    • 编译过程耗时较长,其中最后的opensslgmp-mpfr-sys编译耗时最长,前面讲到的“不做就会报错”的“报错”基本都是在编译gmp-mpfr-sys时产生的。
  7. 编译完成后<代码库路径>/target/release/scryer-prolog.exe"即为输出。(就是一个单文件,无需额外的库文件了)

最后输出的单.exe文件有133MB,我觉得太大了,更成熟的SWI-Prolog只占用44MB(v8.4.0版本)。

作者的README中还提到可以为 scryer-prolog 生成一个.msi安装包,不过我试了一下,生成的安装包就只是简单地把scryer-prolog.exe复制到了C:\Program Files中的一个文件夹里,没啥意义。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK