foreign interface error after upgrade

41 views
Skip to first unread message

Marijn Schraagen

unread,
Oct 27, 2015, 8:49:48 AM10/27/15
to SWI-Prolog
I am using the foreign interface to call Prolog from C++ code. It works well, except that I encountered a garbage collection error today that I was unable to resolve. Since I was using SWI-Prolog 6.6.4 from the official Ubuntu repository, I decided to upgrade to see if this would make any difference for my problem.

I added the repository ppa:swi-prolog/stable and I installed the swi-prolog, swi-prolog-doc and prolog-el packages. Now, I have SWI-Prolog 7.2.3 which I am able to start from a terminal. However, my C++ code doesn't compile anymore. The command that worked with 6.6.4 was g++ -Wall test.cc `pkg-config --cflags --libs swipl`. Now, the line #include <SWI-Prolog.h> resulted in a No such file or directory error.

I found out that the include path provided by pkg-config is incorrect, it returns -fno-strict-aliasing -pthread -I/usr/lib/swi-prlog/include  -pthread -L/usr/lib/swi-prlog/lib/amd64 -lswipl (there is an o missing in /swi-prlog). If I provide the flags by hand (with the missing o) to g++, the code compiles without any problems. However, when execution reaches the statement PlEngine e(argc,argv); there is a [FATAL ERROR: Could not find system resources].

Any idea what the problem could be? Thanks in advance, Marijn


Jan Wielemaker

unread,
Oct 27, 2015, 9:19:54 AM10/27/15
to Marijn Schraagen, SWI-Prolog
On 27-10-15 13:49, Marijn Schraagen wrote:
> I am using the foreign interface to call Prolog from C++ code. It works
> well, except that I encountered a garbage collection error today that I
> was unable to resolve. Since I was using SWI-Prolog 6.6.4 from the
> official Ubuntu repository, I decided to upgrade to see if this would
> make any difference for my problem.
>
> I added the repository ppa:swi-prolog/stable and I installed the
> swi-prolog, swi-prolog-doc and prolog-el packages. Now, I have
> SWI-Prolog 7.2.3 which I am able to start from a terminal. However, my
> C++ code doesn't compile anymore. The command that worked with 6.6.4 was
> g++ -Wall test.cc `pkg-config --cflags --libs swipl`. Now, the line
> #include <SWI-Prolog.h>resulted in a No such file or directoryerror.
>
> I found out that the include path provided by pkg-config is incorrect,
> it returns -fno-strict-aliasing -pthread -I/usr/lib/swi-prlog/include
> -pthread -L/usr/lib/swi-prlog/lib/amd64 -lswipl(there is an o missing in
> /swi-prlog). If I provide the flags by hand (with the missing o) to g++,

Thanks. Think I found it, so the next ppa should be fine.

> the code compiles without any problems. However, when execution reaches
> the statement PlEngine e(argc,argv); there is a [FATAL ERROR: Could not
> find system resources].
>
> Any idea what the problem could be? Thanks in advance, Marijn

My guess that that the way ppas are built cause the final fallback to
find the system resources to fail. See
http://www.swi-prolog.org/FAQ/FindResources.txt for a description of the
issue and work-arounds.

Cheers --- Jan

Marijn Schraagen

unread,
Oct 27, 2015, 9:54:54 AM10/27/15
to SWI-Prolog, marijn.s...@phil.uu.nl
It works again, thanks for the quick reply!

Maybe the FAQ page could mention the default linux/Ubuntu directory for the work-around:
putenv("SWI_HOME_DIR=/usr/lib/swi-prolog");
or if you want to avoid a conversion warning
putenv(const_cast<char *>("SWI_HOME_DIR=/usr/lib/swi-prolog"));


Jan Wielemaker

unread,
Oct 27, 2015, 10:22:57 AM10/27/15
to Marijn Schraagen, SWI-Prolog
On 27-10-15 14:54, Marijn Schraagen wrote:
> It works again, thanks for the quick reply!
>
> Maybe the FAQ page could mention the default linux/Ubuntu directory for
> the work-around:
> |
> putenv("SWI_HOME_DIR=/usr/lib/swi-prolog");

Added a few lines were to find the home. The location varies a lot
between installations (OS, how compiled/installed/...)

> |
> or if you want to avoid a conversion warning
> |
> putenv(const_cast<char*>("SWI_HOME_DIR=/usr/lib/swi-prolog"));
> |

I assume C++ programmers know how to deal with that :)

Thanks --- Jan
Reply all
Reply to author
Forward
0 new messages