Subject: Re: Problems with foreign libraries using dlls

From: Armando Stellato <[email-masked]>
Date: Fri, 03 Aug 2001 17:21:15 +0200

Well, the problem with the CPP version was that the SWI-Prolog win shell is no
standard output, infact the writings appear on a dos shell.
Anyway I've still problems with the pure C version.
I'm sorry if I'm posting so many messages but I've been on this problem for 2
days before posting anything, just to see if i could solve the problem by me,
and today things are getting better, so i prefer to post messages explaining
what i've solved and what i've yet to do to save time to other people who were
going to reply to my msgs.
Thanx again
Armando

Armando Stellato wrote:

> OK, now i succeeded in creating a dll using Visual C++ (i inserted libpl.pl
> into Project\settings\obect/library modules, don't know if it's correct but
> now it compiles!). so...What problem now?
> If i use the examples given in c in the manual, Prolog loads the library
> i've created but when i ask for current_foreign_library/2 it gives me the
> library without any exported function.
> If I use the examples given with the CPP library (like test.cpp) it loads
> the libraries and the functions, but the prolog doesn't write anything in
> output: for example:
> hello/0 returns (as it should be):  hello world, but only because it is
> defined this way:
> PlQuery q("write", PlTermv("hello world\n"));
>   return q.next_solution();
> if I write hello/1 (example: hello(world)): it says me only yes!!! it
> ignores the cout in the c declaration:
> cout << "name = " << A1.name() << ", arity = " << A1.arity() << endl;
> return TRUE;
>
> Well it's three days that i'm fighting against him...help!!
>
> Armando Stellato wrote:
>
> > Hi there,
> > I've gotta some problems in creating DLL containing external predicates
> > for prolog.
> > Before creating my own predicates, I tried to use the examples in the
> > manual.
> > I'm using windows version of SWI-Prolog 'cause of porting problems from
> > other works, but I'm not used to C compilers for Windows.
> > I tried to use 3 different compilers (lcc, Borland 5.5 free compiler and
> >
> > Visual Basic), well, at least I succeeded in using one of them.
> > This is the procedure i followed with lcc compiler:
> >
> > <created file "lowercase.c" from example>
> >
> > from shell: lcc -c lowercase.c
> >
> > <now lowercase.obj has been created>
> >
> > <
> > created "lowercase.def" this way:
> >
> > EXPORTS
> >     pl_lowercase
> >
> > >
> >
> > from shell: lcclnk -dll lowercase.obj libpl.lib lowercase.def
> >
> > <
> > it was important to insert libpl.lib 'cause without this file,  it gave
> > me
> > the following errors:
> >
> > lowercase.obj .text: undefined reference to '_PL_get_atom_chars'
> > lowercase.obj .text: undefined reference to '_PL_warning'
> > lowercase.obj .text: undefined reference to '_PL_unify_atom_chars'
> > lowercase.obj .text: undefined reference to '_PL_register_foreign'
> > >
> >
> > so, once created the dll file, i imported it with
> > load_foreign_library(lowercase), but i obtained only this bad message:
> > it's impossible to find the entry point PL_Warning for the procedure in
> > the dynamic link library CRTDLL.DLL.
> >
> > Is there someone out there that can solve my problem?
> >
> > If you want, you can explain me what to do with Visual C++, but i'd like
> >
> > a step-by-step procedure and a explanation of files to copy from (if
> > there are) SWI-Prolog, the files i've yet copied from the prolog
> > directory are: lib files form lib directory into the lib directory of
> > the c-compilers and the header files into the c-compilers-headers
> > directory.
> >
> > Excuse my poor english and the length of this mail, but i tried to be as
> >
> > clear as possible reporting ev'ry step i've done.
> >
> > Thank u in advance
> >
> > Armando Stellato