Call C from Prolog

658 Views Asked by At

I've built the dll using this command:

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

It created a test.dll.

Prolog code.

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

And this is the C code.

    #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);
    }

And now I call C from Prolog:

ERROR: Exported procedure test.dll:say_hello/1 is not defined

What's wrong? Please, tell me.

0

There are 0 best solutions below