从Prolog打电话给C.

时间:2014-12-01 01:27:39

标签: c prolog ffi swi-prolog

我使用此命令构建了dll:

  
    

" C:\ Program Files(x86)\ swipl \ bin \ swipl-ld.exe" -o test new.cpp pro.pl

  

它创建了一个test.dll。

Prolog代码。

:- module('test.dll', [ say_hello/1 ]).
:- use_module(library(shlib)). 
:- initialization load_foreign_library(foreign('test.dll')).

这是C代码。

    #include <windows.h>
    #include <stdio.h>
    #include <SWI-Prolog.h>

    static foreign_t
    pl_say_hello(term_t to)
    { char *a;

      if ( PL_get_atom_chars(to, &a) )
      { printf("DLL TEST ");

    PL_succeed;
      }

      PL_fail;
    }

    install_t
    install_mylib()
    { PL_register_foreign("say_hello", 1, pl_say_hello, 0);
    }

现在我从Prolog打电话给C:

  

错误:导出的程序test.dll:say_hello / 1未定义

出了什么问题?请告诉我。

0 个答案:

没有答案