Undefined procedure on foreign library in 6.6.4

jon judge <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi,

I successfully installed 6.6.4 using your apt-add-repository
ppa:swi-prolog/stable url (not from source),  All worked perfectly first
time - I can run swipl.

But now I'm hitting issues accessing a foreign library predicate that
appears to build correctly. I've removed nearly all the code to simplify /
reproduce:

#include <SWI-Prolog.h>

static foreign_t testfo(void)
{
	PL_succeed;
}

install_t install_libtestfo()
{
  PL_register_foreign("testfo", 0, testfo, 0);
}

When I build the above from eclipse as a shared object, it compiles no
problem, creating the shared object:

-rwxr-xr-x 1 jon  jon    41531 Apr  2 15:18 libtestfo.so

Now I link to swipl:

# swipl-ld -v -shared -o libtestfo ../testfo.c
	eval `swipl --dump-runtime-variables`
		CC="gcc"
		PLBASE="/usr/lib/swi-prolog"
		PLARCH="i386"
		PLLIBS=""
		PLLIB="-lswipl"
		PLCFLAGS="-fno-strict-aliasing -pthread -fPIC -D_FORTIFY_SOURCE=2 -fPIC
-I/usr/include/ncursesw"
		PLLDFLAGS="-rdynamic -Wl,-Bsymbolic-functions -Wl,-z,relro -g -O2
-fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security
-pthread"
		PLSOEXT="so"
		PLTHREADS="yes"
	gcc -c -fpic -fno-strict-aliasing -pthread -fPIC -D_FORTIFY_SOURCE=2 -fPIC
-I/usr/include/ncursesw -D_REENTRANT -D__SWI_PROLOG__
-I/usr/lib/swi-prolog/include -o ../testfo.o ../testfo.c
	gcc -o libtestfo.so -shared -rdynamic -Wl,-Bsymbolic-functions -Wl,-z,relro
-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat
-Werror=format-security -pthread ../testfo.o -L/usr/lib/swi-prolog/lib/i386
-lswipl
	rm ../testfo.o

.. no errors.  The new library is definitely built.. timestamp updated, and
file size has increased compared to the version above.

-rwxr-xr-x 1 root root 1237082 Apr  2 15:20 libtestfo.so

Check the symbols are in there:

root@phoenix:/home/jon/Dev/testfo/Debug# nm libtestfo.so | grep testfo
0000e4b5 T install_libtestfo
0000e4ab t testfo

.. all ok.

Now in prolog, testfo.pl containing a single line:

:- use_foreign_library(foreign('/home/jon/Dev/testfo/Debug/libtestfo.so')). 

This loads correctly, so it has found the install predicate etc..
5 ?-  
pdt_reload:pdt_reload(['/home/jon/Dev/pl/testfo.pl']).
|    % /home/jon/Dev/pl/testfo.pl compiled 0.00 sec, 5 clauses
true.

But I get undefined procedure when trying to access it:

6 ?- testfo.
ERROR: [Thread pdt_console_client_0_Default Process] toplevel: Undefined
procedure: testfo/0 (DWIM could not correct goal)

It's always tempting to make 1+1=3, but someone else hit the similar
symptoms today:

http://stackoverflow.com/questions/22811055/why-am-i-not-able-to-load-this-c-code-in-prolog-in-linux-but-i-am-able-in-os-x

I have successfully done this before lots of times on 6.2.6 compiled from
source.. but for this install I'm on a completely new machine using
packages, and wondering what I am doing wrong.. / have forgotten / how the
process is different.

Thanks,
Jon.




--
View this message in context: http://swi-prolog.996271.n3.nabble.com/Undefined-procedure-on-foreign-library-in-6-6-4-tp14676.html
Sent from the SWI Prolog mailing list archive at Nabble.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.