SWI-Prolog / issues

Dummy repository for issue tracking
7 stars 3 forks source link

Cannot access predicates from a foreign library on macintosh #36

Closed manubatura closed 8 years ago

manubatura commented 8 years ago

I am able to load a compiled foreign library but not able to see the predicates defined in the foreign library. Can someone help here.

Environment:

Platform: Macintosh Operation System: OSX-Yosemite SWI-Prolog: Pre-built available from swi-prolog.org (Multi-threaded, 64 bits, Version 7.2.3) gcc: 4.2.1

Foreign Module source code:

hello.c

#include <SWI-Prolog.h>

static foreign_t
pl_say_hello(term_t to)
{
 PL_succeed;
}

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

Building the library:

gcc --shared -I/Applications/SWI-Prolog.app/Contents/swipl/include -o hello hello.c /Applications/SWI-Prolog.app/Contents/swipl/lib/x86_64-darwin14.3.0/libswipl.a -lgmp -ltermcap

When I load the foreign library, it loads fine. However, I cannot see the say_hello/1 predicate.

2 ?- load_foreign_library(foreign(hello)).

true.

3 ?- current_foreign_library(A, B).

A = foreign(hello),

B = []

A = foreign(readutil),

B = [read_util:read_line_to_codes(_G950, _G951, _G952), read_util:read_line_to_codes(_G941, _G942), read_util:read_stream_to_codes(_G931, _G932, _G933), read_util:read_stream_to_codes(_G922, _G923)].
JanWielemaker commented 8 years ago

You may need foreign_t install_hello(). That is at least the normal way. I'm also unsure about the link flags. Try using swipl-ld for the compile/link. If that fails in the installation, try at least swipl-ld -v <args> to see how it calls gcc for the Mac.

manubatura commented 8 years ago

Hi Jan,

Thanks for getting back so quickly on this. Your suggestion of using -v with swipl-ld worked. swipl-ld by itself failed, but I used the flags for MAC that swipl-ld using with gcc and it worked. Thanks a lot for your help here.

Regards, Manu