将SWI-Prolog嵌入dll [英] Embedding SWI-Prolog in a dll

查看:244
本文介绍了将SWI-Prolog嵌入dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个C ++库(windows,DLL),我想嵌入swi-prolog的一些功能。

我所做的是:

I'm building a C++ library (windows, DLL) and I'd like to embed swi-prolog for some functionalities.
What I'm doing is:

#include <Windows.h>
#include <SWI-Prolog.h>

BOOL WINAPI DllMain(
    HINSTANCE hinstDLL,  // DLL モジュールのハンドル
    DWORD fdwReason,     // 関数を呼び出す理由
    LPVOID lpvReserved   // 予約済み
)
{
    BOOL result = TRUE;

    switch(fdwReason)
    {
        case DLL_PROCESS_ATTACH:
        {
            char* av[]{"libswipl.dll"};

            _putenv(R"(SWI_HOME_DIR=C:\Program Files (x86)\swipl\)");

            if(!PL_initialise(1, av))
            {
                result = TRUE;
            }
            else
            {
                PL_halt(1);
                result = FALSE;
            }

            break;
        }

        case DLL_PROCESS_DETACH:
        {
            result = PL_cleanup(1);
            break;
        }
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
            break;
    }

    return result;
}

并包含libswipl.lib,从swipl \lib \\ \\ libswipl.dll.a。

and including "libswipl.lib", renamed from "swipl\lib\libswipl.dll.a".

首先它提供错误,因为缺少dll,所以我复制这些在我的可执行文件夹,直到它很高兴(具体来说,libswipl.dll; libgmp-10.dll; pthreadGC2 .dll)。

First it gives errors because of missing dll, so I copied those in my executable folder until it was happy (specifically, libswipl.dll;libgmp-10.dll;pthreadGC2.dll).

我不需要在可执行文件中包含一个pl文件(这是什么swipl-ld?),因为我想通过代码dinamically添加事实和规则以后,所以它是确定初始化与清除状态。

I don't need to include a pl file into the executable (is this what swipl-ld does?) because I would like to add facts and rules dinamically by code later, so it's ok to initialize with a clear state.

我想知道的是,如何摆脱依赖项(SWI_HOME_DIR)并使其独立?

What I'd like to know is, how do I get rid of the dependencies (SWI_HOME_DIR) and make it stand-alone?

推荐答案

我从未使用过SWI-Prolog,而是查看了安装的文件,一些安装在那里的文件似乎需要运行prolog引擎。

I have never used SWI-Prolog, but looking at the installed files, some of the files installed there seem to be required to run the prolog engine.

如果你想将所有内容都嵌入到dll中,那么可能不可能,唯一的方法是修改swi-prolog本身。但这不会容易。

If you mean you want to embed everything into your dll, it would probably not be possible, the only way would be modifying swi-prolog itself. But that won't be easy.

如果您只是不想要安装swi-prolog来让程序运行。您可以创建自己的安装程序,其中包含所有文件以运行swi-prolog,并将其包含在您自己的(子)目录中。您仍然需要设置SWI_HOME_DIR,但是您将知道可执行文件的相对目录。

If you just don't want to require swi-prolog to be installed to have your program running. you can create your own installer which included all files to run swi-prolog, and include it in your own (sub)directory. You still need to set SWI_HOME_DIR, but you will know the relative directory to your executable.

如果不想使用_putenv设置SWI_HOME_DIR,您还可以将Windows系统设置中的SWI_HOME_DIR设置为正确的值。

If you don't want to use _putenv to set SWI_HOME_DIR, you can also set SWI_HOME_DIR in the windows system settings to the correct value.

这篇关于将SWI-Prolog嵌入dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆