For Programmers: Free Programming Magazines  


Home > Archive > Prolog > January 2006 > Calling Prolog predicates from a C program.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Calling Prolog predicates from a C program.
Sujai

2006-01-30, 7:01 pm

Hi all,
I would like to have a standalone executable that makes prolog queries
and prints out the results. Here is my implementation.

/* Start*/
#include"SWI-Prolog.h"
main(int argc,char **argv)
{

if ( !PL_initialise(argc, argv) )
PL_halt(1);
static predicate_t pred_id;
term_t t0=PL_new_term_refs(4);
pred_id=PL_predicate("my_getdata",4,"getdata");
PL_call_predicate(NULL,PL_Q_NORMAL,pred_
id,t0);
}
/* End*/

I am trying to compile this program using the following command.
'plld temp.c -L .'

On doing this, I am getting the following error:
temp.o(.text+0x1a): In function `main':
: undefined reference to `PL_initialise'
temp.o(.text+0x2b): In function `main':
: undefined reference to `PL_halt'
temp.o(.text+0x38): In function `main':
: undefined reference to `PL_new_term_refs'
temp.o(.text+0x52): In function `main':
: undefined reference to `PL_predicate'
temp.o(.text+0x6c): In function `main':
: undefined reference to `PL_call_predicate'
collect2: ld returned 1 exit status
gcc returned code 256
*** plld exit status 1

The libpl.a is in the same directory as the file temp.c


Can someone help me in resolving the linker errors above.

Thanks in advance.
Sujai.

Jan Wielemaker

2006-01-30, 7:01 pm

On 2006-01-30, Sujai <sujai_antony2001@yahoo.com> wrote:
> Hi all,
> I would like to have a standalone executable that makes prolog queries
> and prints out the results. Here is my implementation.
>
> /* Start*/
> #include"SWI-Prolog.h"
> main(int argc,char **argv)
> {
>
> if ( !PL_initialise(argc, argv) )
> PL_halt(1);
> static predicate_t pred_id;
> term_t t0=PL_new_term_refs(4);
> pred_id=PL_predicate("my_getdata",4,"getdata");
> PL_call_predicate(NULL,PL_Q_NORMAL,pred_
id,t0);
> }
> /* End*/
>
> I am trying to compile this program using the following command.
> 'plld temp.c -L .'
>
> On doing this, I am getting the following error:
> temp.o(.text+0x1a): In function `main':
>: undefined reference to `PL_initialise'
> temp.o(.text+0x2b): In function `main':
>: undefined reference to `PL_halt'
> temp.o(.text+0x38): In function `main':
>: undefined reference to `PL_new_term_refs'
> temp.o(.text+0x52): In function `main':
>: undefined reference to `PL_predicate'
> temp.o(.text+0x6c): In function `main':
>: undefined reference to `PL_call_predicate'
> collect2: ld returned 1 exit status
> gcc returned code 256
> *** plld exit status 1
>
> The libpl.a is in the same directory as the file temp.c


It might help a lot to tell us which platform and which version of
SWI-Prolog. You should not need to copy libpl.a (better not). Its
plld's task to add appropriate -I and -L options to the compile and
link commands. Try running

plld -v temp.c

and see what happens.

Cheers --- Jan
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com