How to use swipl within my C++ program?

I compiled and built swipl-devel in this way:


raphy@raphy:~$ git clone --recursive https://github.com/SWI-Prolog/swipl-devel.git

raphy@raphy:~/swipl-devel$ cmake -DCMAKE_INSTALL_PREFIX=/home/raphy/MyPrj/src/swipl-devel/ -DCMAKE_BUILD_TYPE=PGO -DSWIPL_PACKAGES_JAVA=OFF -DBUILD_TESTING=OFF -DINSTALL_TESTS=OFF -DINSTALL_DOCUMENTATION=OFF -GNinja -B builddir -S .

raphy@raphy:~/swipl-devel$ cmake --build builddir --target install -j9

In the CMakeLists.txt file of my project I’ve put :


target_link_directories(${PROJECT_NAME} PUBLIC
    ./src/swipl-devel/lib/swipl/lib
    ./src/swipl-devel/lib/swipl/lib/x86_64-linux
    ./src/swipl-devel/lib/swipl/bin/x86_64-linux
)

target_include_directories(${PROJECT_NAME} PUBLIC
    ./src/swipl-devel/lib/swipl/include
)

target_link_libraries (${PROJECT_NAME} PUBLIC
    swipl
)

In ./src/main.cpp :

#include "SWI-Prolog.h"


            char *av[10];
            int ac = 0;
            av[ac++] = "./swipl-devel/bin/swipl";
            av[ac++] = "-x";
            av[ac++] = "./swiple-devel/lib/swipl/boot.prc";
            av[ac] = NULL;

            PL_initialise(ac, av);
            PL_halt(PL_toplevel() ? 0 : 1);

where boot.prc is in this subfolder :

src/swipl-devel/lib/swipl$ ls
ABI  bin   boot.prc  customize  doc      lib      LICENSE    swipl.home
app  boot  cmake     demo       include  library  README.md

and swipl executable is in this subfolder:

/src/swipl-devel/bin$ ls -lah
total 8.0K
drwxr-xr-x 2 raphy raphy 4.0K May 13 18:45 .
drwxr-xr-x 5 raphy raphy 4.0K May 13 18:45 ..
lrwxrwxrwx 1 raphy raphy   35 May 13 18:45 swipl -> ../lib/swipl/bin/x86_64-linux/swipl
lrwxrwxrwx 1 raphy raphy   38 May 13 18:45 swipl-ld -> ../lib/swipl/bin/x86_64-linux/swipl-ld
lrwxrwxrwx 1 raphy raphy   39 May 13 18:45 swipl-win -> ../lib/swipl/bin/x86_64-linux/swipl-win

Compiling

cmake --build builddir -j9

and executing I get the following error message:

[FATAL ERROR: at Wed May 13 21:41:13 2026
	Could not open resource database "./swiple-devel/lib/swipl/boot.prc": No such file or directory]
Aborted (core dumped)


OS: Ubuntu 24.04

gcc (Ubuntu 14.2.0-4ubuntu2~24.04.1) 14.2.0

What am I doing wrong and/or missing? How to make it work?

Doing in this way:

                char *argv[] = {"hello", "-q"};
                PL_initialise(2, argv);
                PL_halt(PL_toplevel() ? 0 : 1);

I do not get the error message anymore, but, when executing I get: 

```1 ?-
```
which is the prompt for swipl-devl

But what I would like to do is to be able to use swipl within my C++ program
Is this feasible and possible? How to do it?

What is this extra e doing there?

Hi @Jan

It seems the that there should be other errors apart from that typo swiple:

With /src/main :

                char *av[10];
                int ac = 0;
                av[ac++] = "./swipl-devel/bin/swipl";
                av[ac++] = "-x";
                av[ac++] = "./swipl-devel/lib/swipl/boot.prc";
                av[ac] = NULL;


                PL_initialise(ac, av);
                PL_halt(PL_toplevel() ? 0 : 1);

I still get the error message:

[FATAL ERROR: at Thu May 14 09:58:10 2026
	Could not open resource database "./swipl-devel/lib/swipl/boot.prc": No such file or directory]
Aborted (core dumped)

/src/swipl-devel/lib/swipl$ ls
ABI  bin   boot.prc  customize  doc      lib      LICENSE    swipl.home
app  boot  cmake     demo       include  library  README.md

Trying the same, adjusted for my local paths works just fine. Depending on the platform, I’d try tracing system calls. On linux:

strace -o calls.log <exe>

and then search in calls.log to see what is happening.

Make sure you link the a compatible libswipl.so (or whatever it is named on your platform). One of the few things that changed over the years is that it expects an ABI file next to boot.prc that is inspected to validate that the Prolog VM is compatible with the one that created the boot file. In the old days a mismatch often worked to some degree. Now it is rejected.

I tried to build and compile swipl fetching the swipl-devel git repo within MyPrj’s CMakeLists.txt :

FetchContent_Declare(
    swipl
    GIT_REPOSITORY https://github.com/SWI-Prolog/swipl-devel.git
    GIT_TAG master
)
FetchContent_MakeAvailable(swipl)

But during compilation I got this error message:

gmake[2]: *** No rule to make target '_deps/swipl-build/man/utf8proc', needed by 'man/pldoc2tex'.  Stop.
gmake[1]: *** [CMakeFiles/Makefile2:3793: _deps/swipl-build/man/CMakeFiles/pldoc2tex_state.dir/all] Error 2

So…I’m going to stick to my previous method:

raphy@raphy:~/swipl-devel$ cmake -DCMAKE_INSTALL_PREFIX=/home/raphy/MyPrj/src/swipl-devel/ -DCMAKE_BUILD_TYPE=PGO -DSWIPL_PACKAGES_JAVA=OFF -DBUILD_TESTING=OFF -DINSTALL_TESTS=OFF -DINSTALL_DOCUMENTATION=OFF -GNinja -B builddir -S .

raphy@raphy:~/swipl-devel$ cmake --build builddir --target install -j9

And I will trace system calls, as you suggested. I will write down here the output

Output of strace:

raphy@raphy:~$ strace -o calls.log /home/raphy/MyPrj/builddir/MyPrj 
Current path: "/home/raphy"
[FATAL ERROR: at Thu May 14 12:12:58 2026
	Could not open resource database "./swipl-devel/lib/swipl/boot.prc": No such file or directory]
Aborted (core dumped)

In CMakeLists.txt` file:

target_link_directories(${PROJECT_NAME} PUBLIC
    ./src/swipl-devel/lib/swipl/lib
    ./src/swipl-devel/lib/swipl/lib/x86_64-linux
    ./src/swipl-devel/lib/swipl/bin/x86_64-linux
)

target_include_directories(${PROJECT_NAME} PUBLIC
    ./src/swipl-devel/lib/swipl/include
)

target_link_libraries (${PROJECT_NAME} PUBLIC
    swipl
)

raphy@raphy:~/MyPrj/src/swipl-devel/lib/swipl/lib/x86_64-linux$ ls -lah | grep libswipl.so
lrwxrwxrwx 1 raphy raphy   14 May 13 18:45 libswipl.so -> libswipl.so.10
lrwxrwxrwx 1 raphy raphy   18 May 13 18:45 libswipl.so.10 -> libswipl.so.10.1.7
-rw-r--r-- 1 raphy raphy  14M May 13 18:44 libswipl.so.10.1.7

raphy@raphy:~/MyPrj/src/swipl-devel/lib/swipl$ ls
ABI  app  bin  boot  boot.prc  cmake  customize  demo  doc  include  lib  library  LICENSE  README.md  swipl.home

raphy@raphy:~/MyPrj/src/swipl-devel/lib/swipl$ cat ABI
swipl-abi-2-68-b5762387-a5b83da7


I built and compiled again swipl:

raphy@raphy:~$ git clone --recursive https://github.com/SWI-Prolog/swipl-devel.git

raphy@raphy:~/swipl-devel$ cmake -DCMAKE_INSTALL_PREFIX=/home/raphy/MyPrj/src/swipl-devel/ -DCMAKE_BUILD_TYPE=Release -DSWIPL_PACKAGES_JAVA=OFF -DINSTALL_DOCUMENTATION=OFF -GNinja -B builddir -S .

raphy@raphy:~/swipl-devel$ cmake --build builddir --target install -j10

-- Install configuration: "Release"
-- Set non-toolchain portion of runtime path of "/home/raphy/MyPrj/src/swipl-devel/lib/swipl/bin/x86_64-linux/swipl" to "/home/raphy/MyPrj/src/swipl-devel/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/home/raphy/MyPrj/src/swipl-devel/lib/swipl/lib/x86_64-linux/libswipl.so.10.1.7" to "/home/raphy/MyPrj/src/swipl-devel/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/home/raphy/MyPrj/src/swipl-devel/lib/swipl/bin/x86_64-linux/swipl-win" to "/home/raphy/MyPrj/src/swipl-devel/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/home/raphy/MyPrj/src/swipl-devel/lib/swipl/bin/x86_64-linux/swipl-ld" to "/home/raphy/MyPrj/src/swipl-devel/lib/swipl/lib/x86_64-linux"


But I get the same error : 

raphy@raphy:~/MyPrj$ ./builddir/MyPrj
Current path: "/home/raphy/MyPrj"
[FATAL ERROR: at Thu May 14 12:55:25 2026
	Could not open resource database "./swipl-devel/lib/swipl/boot.prc": No such file or directory]
Aborted (core dumped)


raphy@raphy:~$ strace -o calls.log  /home/raphy/MyPrj/builddir/MyPrj
Current path: "/home/raphy"
[FATAL ERROR: at Thu May 14 13:01:32 2026
	Could not open resource database "./swipl-devel/lib/swipl/boot.prc": No such file or directory]
Aborted (core dumped)




Last lines of calls.log :

ioctl(0, TCGETS, {c_iflag=ICRNL|IXON|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(1, TCGETS, {c_iflag=ICRNL|IXON|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(2, TCGETS, {c_iflag=ICRNL|IXON|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
newfstatat(AT_FDCWD, "/home/raphy", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home/raphy", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "./swipl-devel/bin/swipl", 0x7fff38e53cc0, 0) = -1 ENOENT (No such file or directory)
readlink("./swipl-devel/bin/swipl", 0x7fff38e55d60, 4095) = -1 ENOENT (No such file or directory)
getcwd("/home/raphy", 4096)             = 12
newfstatat(AT_FDCWD, "/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home/raphy/swipl-devel/bin", 0x7fff38e4cbc0, 0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/raphy/swipl-devel/swipl.home", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/raphy/MyPrj/src/swipl-devel/lib/swipl/ABI", O_RDONLY) = 13
ioctl(13, TCGETS, 0x7fff38e50b70)       = -1 ENOTTY (Inappropriate ioctl for device)
fcntl(13, F_SETFD, FD_CLOEXEC)          = 0
read(13, "swipl-abi-2-68-b5762387-a5b83da7"..., 4096) = 33
close(13)                               = 0
openat(AT_FDCWD, "./swipl-devel/bin/swipl", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "./swipl-devel/lib/swipl/boot.prc", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, "[FATAL ERROR: at Thu May 14 13:0"..., 43) = 43
write(2, "Could not open resource database"..., 94) = 94
write(2, "]\n", 2)                      = 2
rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0
gettid()                                = 153682
getpid()                                = 153682
tgkill(153682, 153682, SIGABRT)         = 0
--- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=153682, si_uid=1000} ---
+++ killed by SIGABRT (core dumped) +++

@jan What does “Inappropriate ioctl for device” mean ?

And why

newfstatat(AT_FDCWD, "./swipl-devel/bin/swipl", 0x7ffc02a43000, 0) = -1 ENOENT (No such file or directory)

?

Looking for suggestions about how to overcome the issue and make swipl work

Trying to understand what’s going on ..

The "Inappropriate ioctl for device" error in Ubuntu 24.04 can occur due to compatibility issues with certain operations or drivers. Check for kernel updates or specific driver support for your hardware

My system is updated:

raphy@raphy:~$ sudo apt-get full-upgradeReading package lists… DoneBuilding dependency tree… DoneReading state information… DoneCalculating upgrade… Done0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.


The ABI is actually read:

openat(AT_FDCWD, "/home/raphy/MyPrj/src/swipl-devel/lib/swipl/ABI", O_RDONLY) = 13

But, on the other hands, it says:

openat(AT_FDCWD, "./swipl-devel/bin/swipl", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "./swipl-devel/lib/swipl/boot.prc", O_RDONLY) = -1 ENOENT (No such file or directory)

What could be the reasons for Inappropriate ioctl for device error message?

Looking around I’ve found this hint: https://stackoverflow.com/questions/72445825/gpg-error-inappropriate-ioctl-for-device but tried, and it didn’t work:

raphy@raphy:~/Grasp$ export GPG_TTY=$(tty)
raphy@raphy:~/Grasp$ ./builddir/Grasp
Current path: "/home/raphy/Grasp"
[FATAL ERROR: at Fri May 15 09:45:25 2026
	Could not open resource database "./swipl-devel/lib/swipl/boot.prc": No such file or directory]
Aborted (core dumped)

It doesn’t clone the submodules. To build from git, you need to init the submodules (recursively).

I think it is from calling isatty() to detect whether a stream is a tty. I would not worry.

That is what is nailing you. Wrong directory, wrong path, something weird with permissions, …

I’d compile for debugging. You can than add -d initialize to get some more messages on the startup or attach a debugger and step through the initialization. Looks like some weird local problem.

P.s. SWI-Prolog installs CMake import files in <home>/lib/cmake.

I’ve built and compiled swipl in Debug mode and used gdb debugger during the program execution.

Building and compiling of swipl :

raphy@raphy:~$ git clone --recurse-submodule https://github.com/SWI-Prolog/swipl-devel.git

Submodule 'bench' (https://github.com/SWI-Prolog/bench.git) registered for path 'bench'
Submodule 'debian' (https://github.com/SWI-Prolog/distro-debian.git) registered for path 'debian'
Submodule 'packages/PDT' (https://github.com/SWI-Prolog/packages-PDT.git) registered for path 'packages/PDT'
Submodule 'packages/RDF' (https://github.com/SWI-Prolog/packages-RDF.git) registered for path 'packages/RDF'
Submodule 'packages/archive' (https://github.com/SWI-Prolog/packages-archive.git) registered for path 'packages/archive'
Submodule 'packages/bdb' (https://github.com/SWI-Prolog/packages-bdb.git) registered for path 'packages/bdb'
Submodule 'packages/chr' (https://github.com/SWI-Prolog/packages-chr.git) registered for path 'packages/chr'
Submodule 'packages/clib' (https://github.com/SWI-Prolog/packages-clib.git) registered for path 'packages/clib'
Submodule 'packages/clpqr' (https://github.com/SWI-Prolog/packages-clpqr.git) registered for path 'packages/clpqr'
Submodule 'packages/cpp' (https://github.com/SWI-Prolog/packages-cpp.git) registered for path 'packages/cpp'
Submodule 'packages/cql' (https://github.com/SWI-Prolog/packages-cql.git) registered for path 'packages/cql'
Submodule 'packages/http' (https://github.com/SWI-Prolog/packages-http.git) registered for path 'packages/http'
Submodule 'packages/inclpr' (https://github.com/SWI-Prolog/packages-inclpr.git) registered for path 'packages/inclpr'
Submodule 'packages/jpl' (https://github.com/SWI-Prolog/packages-jpl.git) registered for path 'packages/jpl'
Submodule 'packages/json' (https://github.com/SWI-Prolog/packages-json.git) registered for path 'packages/json'
Submodule 'packages/libedit' (https://github.com/SWI-Prolog/packages-libedit.git) registered for path 'packages/libedit'
Submodule 'packages/ltx2htm' (https://github.com/SWI-Prolog/packages-ltx2htm.git) registered for path 'packages/ltx2htm'
Submodule 'packages/mqi' (https://github.com/SWI-Prolog/packages-mqi.git) registered for path 'packages/mqi'
Submodule 'packages/nlp' (https://github.com/SWI-Prolog/packages-nlp.git) registered for path 'packages/nlp'
Submodule 'packages/odbc' (https://github.com/SWI-Prolog/packages-odbc.git) registered for path 'packages/odbc'
Submodule 'packages/paxos' (https://github.com/SWI-Prolog/packages-paxos.git) registered for path 'packages/paxos'
Submodule 'packages/pcre' (https://github.com/SWI-Prolog/packages-pcre.git) registered for path 'packages/pcre'
Submodule 'packages/pengines' (https://github.com/SWI-Prolog/packages-pengines.git) registered for path 'packages/pengines'
Submodule 'packages/pldoc' (https://github.com/SWI-Prolog/packages-pldoc.git) registered for path 'packages/pldoc'
Submodule 'packages/plunit' (https://github.com/SWI-Prolog/packages-plunit.git) registered for path 'packages/plunit'
Submodule 'packages/protobufs' (https://github.com/SWI-Prolog/contrib-protobufs.git) registered for path 'packages/protobufs'
Submodule 'packages/redis' (https://github.com/SWI-Prolog/packages-redis.git) registered for path 'packages/redis'
Submodule 'packages/semweb' (https://github.com/SWI-Prolog/packages-semweb.git) registered for path 'packages/semweb'
Submodule 'packages/sgml' (https://github.com/SWI-Prolog/packages-sgml.git) registered for path 'packages/sgml'
Submodule 'packages/ssl' (https://github.com/SWI-Prolog/packages-ssl.git) registered for path 'packages/ssl'
Submodule 'packages/stomp' (https://github.com/SWI-Prolog/packages-stomp.git) registered for path 'packages/stomp'
Submodule 'packages/sweep' (https://github.com/SWI-Prolog/packages-sweep.git) registered for path 'packages/sweep'
Submodule 'packages/swipy' (https://github.com/SWI-Prolog/packages-swipy) registered for path 'packages/swipy'
Submodule 'packages/table' (https://github.com/SWI-Prolog/packages-table.git) registered for path 'packages/table'
Submodule 'packages/tipc' (https://github.com/SWI-Prolog/contrib-tipc.git) registered for path 'packages/tipc'
Submodule 'packages/utf8proc' (https://github.com/SWI-Prolog/packages-utf8proc.git) registered for path 'packages/utf8proc'
Submodule 'packages/windows' (https://github.com/SWI-Prolog/packages-windows.git) registered for path 'packages/windows'
Submodule 'packages/xpce' (https://github.com/SWI-Prolog/packages-xpce.git) registered for path 'packages/xpce'
Submodule 'packages/yaml' (https://github.com/SWI-Prolog/packages-yaml.git) registered for path 'packages/yaml'
Submodule 'packages/zlib' (https://github.com/SWI-Prolog/packages-zlib.git) registered for path 'packages/zlib'

raphy@raphy:~/swipl-devel$ git submodule init
raphy@raphy:~/swipl-devel$ git submodule update

raphy@raphy:~/swipl-devel$ cmake -DCMAKE_INSTALL_PREFIX=/home/raphy/Grasp/src/swipl-devel/ -DCMAKE_BUILD_TYPE=DEBUG -DSWIPL_PACKAGES_JAVA=OFF -DSWIPL_PACKAGES_GUI=OFF -DBUILD_TESTING=OFF -DINSTALL_TESTS=OFF -DSWIPL_PACKAGES_ODBC=OFF -DINSTALL_DOCUMENTATION=OFF -GNinja -B builddir -S .

raphy@raphy:~/swipl-devel$ cmake --build builddir --target install -j9

[1085/1086] Install the project...
-- Install configuration: "DEBUG"
-- Set non-toolchain portion of runtime path of "/home/raphy/Grasp/src/swipl-devel/lib/swipl/bin/x86_64-linux/swipl" to "/home/raphy/Grasp/src/swipl-devel/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/home/raphy/Grasp/src/swipl-devel/lib/swipl/lib/x86_64-linux/libswipl.so.10.1.7" to "/home/raphy/Grasp/src/swipl-devel/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/home/raphy/Grasp/src/swipl-devel/lib/swipl/bin/x86_64-linux/swipl-win" to "/home/raphy/Grasp/src/swipl-devel/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/home/raphy/Grasp/src/swipl-devel/lib/swipl/bin/x86_64-linux/swipl-ld" to "/home/raphy/Grasp/src/swipl-devel/lib/swipl/lib/x86_64-linux"

raphy@raphy:~/Grasp/src/swipl-devel$ ls -lah
total 20K
drwxrwxr-x  5 raphy raphy 4.0K May 15 10:29 .
drwxr-xr-x 79 raphy raphy 4.0K May 15 10:20 ..
drwxr-xr-x  2 raphy raphy 4.0K May 15 10:29 bin
drwxrwxr-x  4 raphy raphy 4.0K May 15 10:29 lib
drwxrwxr-x  4 raphy raphy 4.0K May 15 10:29 share



raphy@raphy:~/Grasp/src/swipl-devel$ ls -lah ./lib/
total 16K
drwxrwxr-x  4 raphy raphy 4.0K Feb 25 09:41 .
drwxr-xr-x  5 raphy raphy 4.0K Feb 25 09:41 ..
drwxrwxr-x  3 raphy raphy 4.0K Feb 25 09:41 cmake
drwxrwxr-x 12 raphy raphy 4.0K Feb 25 09:41 swipl

raphy@raphy:~/Grasp/src/swipl-devel$ ls -lah ./bin/
total 8.0K
drwxr-xr-x 2 raphy raphy 4.0K May 15 10:29 .
drwxrwxr-x 5 raphy raphy 4.0K May 15 10:29 ..
lrwxrwxrwx 1 raphy raphy   35 May 15 10:29 swipl -> ../lib/swipl/bin/x86_64-linux/swipl
lrwxrwxrwx 1 raphy raphy   38 May 15 10:29 swipl-ld -> ../lib/swipl/bin/x86_64-linux/swipl-ld
lrwxrwxrwx 1 raphy raphy   39 May 15 10:29 swipl-win -> ../lib/swipl/bin/x86_64-linux/swipl-win

In CMakeLists.txt file :

raphy@raphy:~/Grasp$ nano CMakeLists.txt :

target_link_directories(${PROJECT_NAME} PUBLIC
    ./src/swipl-devel/lib/swipl/lib
    ./src/swipl-devel/lib/swipl/lib/x86_64-linux 
    ./src/swipl-devel/lib/swipl/bin/x86_64-linux
)


target_include_directories(${PROJECT_NAME} PUBLIC
    ./src/swipl-devel/lib/swipl/include
)

target_link_libraries (${PROJECT_NAME} PUBLIC
    swipl
)

raphy@raphy:~/Grasp$ cmake --build builddir/

Executed the program with the debugger gdb :

raphy@raphy:~/Grasp$ gdb ./builddir/Grasp
GNU gdb (Ubuntu 15.1-1ubuntu1~24.04.1) 15.1
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./builddir/Grasp...
(gdb) watch PL_initialise
Hardware watchpoint 1: PL_initialise
(gdb) run
Starting program: /home/raphy/Grasp/builddir/Grasp 

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n]) n
Debuginfod has been disabled.
To make this setting permanent, add 'set debuginfod enabled off' to .gdbinit.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffdebff6c0 (LWP 7474)]
[New Thread 0x7fffde3fe6c0 (LWP 7475)]
[New Thread 0x7fffddbfd6c0 (LWP 7476)]
[New Thread 0x7fffdd3fc6c0 (LWP 7477)]
[New Thread 0x7fffdcbfb6c0 (LWP 7478)]
[New Thread 0x7fffdc3fa6c0 (LWP 7479)]
[New Thread 0x7fffdbbf96c0 (LWP 7480)]
[New Thread 0x7fffdb3f86c0 (LWP 7481)]
[New Thread 0x7fffdabf76c0 (LWP 7482)]
[New Thread 0x7fffd3fff6c0 (LWP 7483)]
[New Thread 0x7fffda3f66c0 (LWP 7484)]
[New Thread 0x7fffd9bcd6c0 (LWP 7485)]
[New Thread 0x7fffd93bd6c0 (LWP 7486)]
Current path: "/home/raphy/Grasp"
[Detaching after vfork from child process 7488]
[Detaching after vfork from child process 7490]
[Detaching after vfork from child process 7492]
[Detaching after vfork from child process 7494]
[Detaching after vfork from child process 7496]
[New Thread 0x7fffd37fe6c0 (LWP 7498)]
[FATAL ERROR: at Fri May 15 10:48:34 2026
	Could not open resource database "./swipl-devel/lib/swipl/boot.prc": No such file or directory]

Thread 1 "Grasp" received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>)
    at ./nptl/pthread_kill.c:44
warning: 44	./nptl/pthread_kill.c: No such file or directory
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007fffe564527e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007fffe56288ff in __GI_abort () at ./stdlib/abort.c:79
#5  0x00007fffed626fc9 in PL_abort_process () at /home/raphy/swipl-devel/src/pl-fli.c:5109
#6  0x00007fffed5a00ed in vfatalError (fm=0x7fffed6a33b8 "Could not open resource database \"%s\": %s", args=0x7fffffff9e80)
    at /home/raphy/swipl-devel/src/pl-init.c:2174
#7  0x00007fffed59f71d in fatalError (fm=0x7fffed6a33b8 "Could not open resource database \"%s\": %s")
    at /home/raphy/swipl-devel/src/pl-init.c:1968
#8  0x00007fffed59d2a3 in openResourceDB (is_hash_bang=false) at /home/raphy/swipl-devel/src/pl-init.c:1204
#9  0x00007fffed59df0d in PL_initialise (argc=0, argv=0x5555577f45e0) at /home/raphy/swipl-devel/src/pl-init.c:1409

Why does it look for this path:

in PL_abort_process () at /home/raphy/swipl-devel/src/pl-fli.c:5109
#6  0x00007fffed5a00ed in vfatalError (fm=0x7fffed6a33b8 "Could not open resource database \"%s\": %s",

if I specified the INSTALL_PREFIX

-DCMAKE_INSTALL_PREFIX=/home/raphy/Grasp/src/swipl-devel/

cmake --build builddir --target install -j9

and like it is defined in SWIPLConfig.cmake file ? :

raphy@raphy:~/Grasp/src/swipl-devel/lib/cmake/swipl$ cat SWIPLConfig.cmake 

####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was SWIPLConfig.cmake.in                            ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

####################################################################################

# Version information
set(SWIPL_VERSION_COUNT 3)
set(SWIPL_VERSION_MAJOR 10)
set(SWIPL_VERSION_MINOR 1)
set(SWIPL_VERSION_PATCH 7)
set(SWIPL_VERSION_STRING 10.1.7)

# Location suitable for passing to PL_initialise() as argv[0]
set(SWIPL_EXECUTABLE "${PACKAGE_PREFIX_DIR}/lib/swipl/bin/x86_64-linux/swipl")

# Exported targets
include("${CMAKE_CURRENT_LIST_DIR}/SWIPLTargets.cmake")



raphy@raphy:~/Grasp/src/swipl-devel/lib/cmake/swipl$ cat SWIPLTargets-debug.cmake 
#----------------------------------------------------------------
# Generated CMake target import file for configuration "DEBUG".
#----------------------------------------------------------------

# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)

# Import target "swipl::swipl" for configuration "DEBUG"
set_property(TARGET swipl::swipl APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(swipl::swipl PROPERTIES
  IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/lib/swipl/bin/x86_64-linux/swipl"
  )

list(APPEND _cmake_import_check_targets swipl::swipl )
list(APPEND _cmake_import_check_files_for_swipl::swipl "${_IMPORT_PREFIX}/lib/swipl/bin/x86_64-linux/swipl" )

# Import target "swipl::libswipl" for configuration "DEBUG"
set_property(TARGET swipl::libswipl APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(swipl::libswipl PROPERTIES
  IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/lib/swipl/lib/x86_64-linux/libswipl.so.10.1.7"
  IMPORTED_SONAME_DEBUG "libswipl.so.10"
  )

list(APPEND _cmake_import_check_targets swipl::libswipl )
list(APPEND _cmake_import_check_files_for_swipl::libswipl "${_IMPORT_PREFIX}/lib/swipl/lib/x86_64-linux/libswipl.so.10.1.7" )

# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)

What do I have to do to make it work?

I really do not understand why this happens:

raphy@raphy:~/Grasp$ gdb /home/raphy/Grasp/builddir/Grasp


[FATAL ERROR: at Fri May 15 13:15:21 2026
	Could not open resource database "./swipl-devel/lib/swipl/boot.prc": No such file or directory]

Thread 1 "Grasp" received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
warning: 44	./nptl/pthread_kill.c: No such file or directory
(gdb) 
(gdb) 
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007fffe564527e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007fffe56288ff in __GI_abort () at ./stdlib/abort.c:79
#5  0x00007fffed626fc9 in PL_abort_process () at /home/raphy/swipl-devel/src/pl-fli.c:5109    // <----------------- ????
#6  0x00007fffed5a00ed in vfatalError (fm=0x7fffed6a33b8 "Could not open resource database \"%s\": %s", args=0x7fffffff9e80) at /home/raphy/swipl-devel/src/pl-init.c:2174
#7  0x00007fffed59f71d in fatalError (fm=0x7fffed6a33b8 "Could not open resource database \"%s\": %s") at /home/raphy/swipl-devel/src/pl-init.c:1968
#8  0x00007fffed59d2a3 in openResourceDB (is_hash_bang=false) at /home/raphy/swipl-devel/src/pl-init.c:1204
#9  0x00007fffed59df0d in PL_initialise (argc=0, argv=0x5555577f2f50) at /home/raphy/swipl-devel/src/pl-init.c:1409


Why does it look here in /home/raphy/swipl-devel/

Could not open resource database \"%s\": %s", args=0x7fffffff9e80) at /home/raphy/swipl-devel/src/pl-init.c:2174

and not in /home/raphy/Grasp/src/swipl-devel where the files have been installed ?

And what should I do to make it work?

Looking forward to kind help

@jan

I tried to directly include swipl in CMakeLists.txt using FetchContent :

FetchContent_Declare(
    swipl
    GIT_REPOSITORY https://github.com/SWI-Prolog/swipl-devel.git
    GIT_TAG master
)
FetchContent_MakeAvailable(swipl)

target_link_libraries (${PROJECT_NAME} PUBLIC
    swipl
)```


raphy@raphy:~/Grasp$ cmake -B builddir -DRATS_BUILD_TESTS=OFF -DWITH_BENCHMARK_TOOLS=FALSE -DOPENSSL_ROOT_DIR="/usr/local/ssl/" -DEigen3_DIR="/usr/include/eigen3" -DSWIPL_PACKAGES_JAVA=OFF -DSWIPL_PACKAGES_GUI=OFF -DBUILD_TESTING=OFF -DINSTALL_TESTS=OFF -DSWIPL_PACKAGES_ODBC=OFF -DINSTALL_DOCUMENTATION=OFF -Wno-author

Cloning into 'swipl-src'...
Already on 'master'
Your branch is up to date with 'origin/master'.
Submodule 'bench' (https://github.com/SWI-Prolog/bench.git) registered for path 'bench'
Submodule 'debian' (https://github.com/SWI-Prolog/distro-debian.git) registered for path 'debian'
Submodule 'packages/PDT' (https://github.com/SWI-Prolog/packages-PDT.git) registered for path 'packages/PDT'
Submodule 'packages/RDF' (https://github.com/SWI-Prolog/packages-RDF.git) registered for path 'packages/RDF'
Submodule 'packages/archive' (https://github.com/SWI-Prolog/packages-archive.git) registered for path 'packages/archive'
Submodule 'packages/bdb' (https://github.com/SWI-Prolog/packages-bdb.git) registered for path 'packages/bdb'
Submodule 'packages/chr' (https://github.com/SWI-Prolog/packages-chr.git) registered for path 'packages/chr'
Submodule 'packages/clib' (https://github.com/SWI-Prolog/packages-clib.git) registered for path 'packages/clib'
Submodule 'packages/clpqr' (https://github.com/SWI-Prolog/packages-clpqr.git) registered for path 'packages/clpqr'
Submodule 'packages/cpp' (https://github.com/SWI-Prolog/packages-cpp.git) registered for path 'packages/cpp'
Submodule 'packages/cql' (https://github.com/SWI-Prolog/packages-cql.git) registered for path 'packages/cql'
Submodule 'packages/http' (https://github.com/SWI-Prolog/packages-http.git) registered for path 'packages/http'
Submodule 'packages/inclpr' (https://github.com/SWI-Prolog/packages-inclpr.git) registered for path 'packages/inclpr'
Submodule 'packages/jpl' (https://github.com/SWI-Prolog/packages-jpl.git) registered for path 'packages/jpl'
Submodule 'packages/json' (https://github.com/SWI-Prolog/packages-json.git) registered for path 'packages/json'
Submodule 'packages/libedit' (https://github.com/SWI-Prolog/packages-libedit.git) registered for path 'packages/libedit'
Submodule 'packages/ltx2htm' (https://github.com/SWI-Prolog/packages-ltx2htm.git) registered for path 'packages/ltx2htm'
Submodule 'packages/mqi' (https://github.com/SWI-Prolog/packages-mqi.git) registered for path 'packages/mqi'
Submodule 'packages/nlp' (https://github.com/SWI-Prolog/packages-nlp.git) registered for path 'packages/nlp'
Submodule 'packages/odbc' (https://github.com/SWI-Prolog/packages-odbc.git) registered for path 'packages/odbc'
Submodule 'packages/paxos' (https://github.com/SWI-Prolog/packages-paxos.git) registered for path 'packages/paxos'
Submodule 'packages/pcre' (https://github.com/SWI-Prolog/packages-pcre.git) registered for path 'packages/pcre'
Submodule 'packages/pengines' (https://github.com/SWI-Prolog/packages-pengines.git) registered for path 'packages/pengines'
Submodule 'packages/pldoc' (https://github.com/SWI-Prolog/packages-pldoc.git) registered for path 'packages/pldoc'
Submodule 'packages/plunit' (https://github.com/SWI-Prolog/packages-plunit.git) registered for path 'packages/plunit'
Submodule 'packages/protobufs' (https://github.com/SWI-Prolog/contrib-protobufs.git) registered for path 'packages/protobufs'
Submodule 'packages/redis' (https://github.com/SWI-Prolog/packages-redis.git) registered for path 'packages/redis'
Submodule 'packages/semweb' (https://github.com/SWI-Prolog/packages-semweb.git) registered for path 'packages/semweb'
Submodule 'packages/sgml' (https://github.com/SWI-Prolog/packages-sgml.git) registered for path 'packages/sgml'
Submodule 'packages/ssl' (https://github.com/SWI-Prolog/packages-ssl.git) registered for path 'packages/ssl'
Submodule 'packages/stomp' (https://github.com/SWI-Prolog/packages-stomp.git) registered for path 'packages/stomp'
Submodule 'packages/sweep' (https://github.com/SWI-Prolog/packages-sweep.git) registered for path 'packages/sweep'
Submodule 'packages/swipy' (https://github.com/SWI-Prolog/packages-swipy) registered for path 'packages/swipy'
Submodule 'packages/table' (https://github.com/SWI-Prolog/packages-table.git) registered for path 'packages/table'
Submodule 'packages/tipc' (https://github.com/SWI-Prolog/contrib-tipc.git) registered for path 'packages/tipc'
Submodule 'packages/utf8proc' (https://github.com/SWI-Prolog/packages-utf8proc.git) registered for path 'packages/utf8proc'
Submodule 'packages/windows' (https://github.com/SWI-Prolog/packages-windows.git) registered for path 'packages/windows'
Submodule 'packages/xpce' (https://github.com/SWI-Prolog/packages-xpce.git) registered for path 'packages/xpce'
Submodule 'packages/yaml' (https://github.com/SWI-Prolog/packages-yaml.git) registered for path 'packages/yaml'
Submodule 'packages/zlib' (https://github.com/SWI-Prolog/packages-zlib.git) registered for path 'packages/zlib'


But I get the following error message :

CMake Error at CMakeLists.txt:1070 (target_link_libraries):
  Target "swipl" of type EXECUTABLE may not be linked into another target.
  One may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

It seems that I cannot link the target library `swipl` when using FetchContent with the swipl github repo

And during compilation phase I get this other error message:

raphy@raphy:~/Grasp$ cmake --build builddir -j9

ERROR: [Thread main] Prolog initialisation failed:
ERROR: [Thread main] script_file `'/home/raphy/Grasp/builddir/home/library/prolog_qlfmake.pl'' does not exist
gmake[2]: *** [_deps/swipl-build/src/CMakeFiles/library_qlf.dir/build.make:73: _deps/swipl-build/src/__library_QLF_files__] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:1650: _deps/swipl-build/src/CMakeFiles/library_qlf.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....


Update:

Putting in CMakeLists.txt :

target_link_libraries (${PROJECT_NAME} PUBLIC
    qsave_program(swipl, [goal=my_main_predicate, global=128000])
)

I solved the first error message

But, still, the compilation phase gives the following error :

raphy@raphy:~/Grasp$ cmake --build builddir -j10
ERROR: [Thread main] Prolog initialisation failed:
ERROR: [Thread main] script_file `'/home/raphy/Grasp/builddir/home/library/prolog_qlfmake.pl'' does not exist
gmake[2]: *** [_deps/swipl-build/src/CMakeFiles/library_qlf.dir/build.make:73: _deps/swipl-build/src/__library_QLF_files__] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:1650: _deps/swipl-build/src/CMakeFiles/library_qlf.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....


Why it says “prolog_glfmake.pl does not exist” if it is actually present?

https://github.com/SWI-Prolog/swipl-devel/blob/1f1b778f543161fd2e0d61afe64ebba546b48ef1/library/prolog_qlfmake.pl


raphy@raphy:~/Grasp/builddir/_deps/swipl-build/home/library$ ls -lah | grep prolog_qlfmake
lrwxrwxrwx  1 raphy raphy   44 May 15 14:08 prolog_qlfmake.pl -> ../../../swipl-src/library/prolog_qlfmake.pl



raphy@raphy:~/Grasp/builddir/_deps/swipl-src/library$ ls -lah | grep prolog_qlfmake.pl 
-rw-rw-r--  1 raphy raphy  17K May 15 14:01 prolog_qlfmake.pl

What am I doing wrong and/or missing? How to make it work?

First of all, as you are just trying to start the boot.prc file, I’d suggest making sure the home is found and omit the -x. Possibly no option is good enough as it is now quite keen to find a compatible home and the last resort is to try the compiled-in default. If all fails, you really have to step through some of the stuff in PL_initialise() that makes it find the home and resource file.

Surely you want libswipl as swipl is the executable. Whether that works is not clear as it might just build libswipl.so without the stuff it needs to run. You have to build the toplevel target to get a working system.

Omitting the -x in the building phase, causes the following error message during the compilation phase:

raphy@raphy:~/swipl-devel$ cmake -DCMAKE_INSTALL_PREFIX=/home/raphy/Grasp/src/swipl-devel/ -DCMAKE_BUILD_TYPE=DEBUG -GNinja -B builddir -S .

raphy@raphy:~/swipl-devel$ cmake --build builddir --target install -j9
ninja: error: 'man/utf8proc', needed by 'man/pldoc2tex', missing and no known rule to make it

libswipl in FetchContent :

FetchContent_Declare(
    libswipl
    GIT_REPOSITORY https://github.com/SWI-Prolog/swipl-devel.git
    GIT_TAG master
)
FetchContent_MakeAvailable(libswipl)


target_link_libraries (${PROJECT_NAME} PUBLIC
    swipl
)

gives this error message:

CMake Error at CMakeLists.txt:1069 (target_link_libraries):
  Target "swipl" of type EXECUTABLE may not be linked into another target.
  One may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

Tried to build and compile without setting INSTALL_PREFIX :

raphy@raphy:~/swipl-devel$ cmake -B builddir

-- Build files have been written to: /home/raphy/swipl-devel/builddir

raphy@raphy:~/swipl-devel$ cmake --build builddir

raphy@raphy:~/swipl-devel$ cmake --build builddir
[ 60%] Built target sgml
gmake[2]: *** No rule to make target 'man/utf8proc', needed by 'man/pldoc2tex'.  Stop.
gmake[1]: *** [CMakeFiles/Makefile2:3917: man/CMakeFiles/pldoc2tex_state.dir/all] Error 2
gmake: *** [Makefile:166: all] Error 2


With DOCUMENTATION=OFF : 

```
raphy@raphy:~/swipl-devel$ cmake -B builddir -DINSTALL_DOCUMENTATION=OFF

raphy@raphy:~/swipl-devel$ cmake -B builddir

[100%] QLF compile library
[100%] Built target library_qlf
[100%] Building C object src/CMakeFiles/swipl-win.dir/pl-main.c.o
[100%] Linking C executable swipl-win
[100%] Built target swipl-win
[100%] Building C object src/CMakeFiles/swipl-ld.dir/swipl-ld.c.o
[100%] Linking C executable swipl-ld
[100%] Built target swipl-ld
[100%] Generating tests/test_certs/generated
[100%] Built target test_certificates
raphy@raphy:~/swipl-devel$ 

raphy@raphy:~/swipl-devel/builddir$ sudo make install

[100%] Built target tipc
[100%] QLF compile library
[100%] Built target library_qlf
[100%] Built target swipl-win
[100%] Built target swipl-ld
[100%] Built target test_certificates
Install the project...
-- Install configuration: "RelWithDebInfo"
-- Set non-toolchain portion of runtime path of "/usr/local/lib/swipl/bin/x86_64-linux/swipl" to "/usr/local/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/usr/local/lib/swipl/lib/x86_64-linux/libswipl.so.10.1.7" to "/usr/local/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/usr/local/lib/swipl/bin/x86_64-linux/swipl-win" to "/usr/local/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/usr/local/lib/swipl/bin/x86_64-linux/swipl-ld" to "/usr/local/lib/swipl/lib/x86_64-linux"

raphy@raphy:~$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 10.1.7-22-g1f1b778f5)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org

1 ?- 


Where are the header files required within my main.cpp C++ program? : 

raphy@raphy:/usr/local/include$ ls -lah | grep swipl
raphy@raphy:/usr/local/include$ 




You want to link against libswipl … Target swipl is the executable.

Everything is contained in <prefix>/lib/swipl. There you find the includes and the CMake import files that you can use with CMake find_package().

I’ve set CMAKE_PREFIX_PATH :

raphy@raphy:~$ echo $CMAKE_PREFIX_PATH
/usr/local/lib/swipl

and I’ve set swipl_DIR :

raphy@raphy:~/Grasp$ export swipl_DIR=/usr/local/lib/swipl/cmake


In CMakeLists.txt :

set (CMAKE_MODULE_PATH
    ${CMAKE_MODULE_PATH}
    ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules
)

find_package(
    swipl REQUIRED
)

cmake-modules folder:

raphy@raphy:~/Grasp$ nano ./cmake-modules/Find.swipl.cmake

find_path(swipl_INCLUDE_DIR
    NAMES swipl_include
)

find_library(swipl_LIBRARY
    NAMES libswipl
    PATHS "/usr/local/lib/swipl/lib/x86_64-linux"
)

set (swipl_LIBRARY "/usr/local/lib/swipl/lib/x86_64-linux")
set (swipl_INCLUDE_DIR "/usr/local/lib/swipl/include")

mark_as_advanced(swipl_INCLUDE_DIR swipl_LIBRARY)

But, still, I get this error message:

CMake Error at CMakeLists.txt:140 (find_package):
  Could not find a package configuration file provided by "swipl" with any of
  the following names:

    swipl.cps
    swiplConfig.cmake
    swipl-config.cmake

  Add the installation prefix of "swipl" to CMAKE_PREFIX_PATH or set
  "swipl_DIR" to a directory containing one of the above files.  If "swipl"
  provides a separate development package or SDK, be sure it has been
  installed.

What should I do @jan ? Thank you in advance

Hi @jan

I tried to install swipl using the PPA Repository for Ubuntu:

raphy@raphy:~$ sudo apt-add-repository ppa:swi-prolog/stable
PPA publishes dbgsym, you may need to include 'main/debug' component
Repository: 'Types: deb
URIs: https://ppa.launchpadcontent.net/swi-prolog/stable/ubuntu/
Suites: noble
Components: main
'
Description:
Comprehensive Prolog implementation with extensive libraries and development tools.   Primarily targetted at teaching, RDF processing and web-related tasks, such as creating web services or analysing web content.


raphy@raphy:~$ sudo apt-get install swi-prolog
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  swi-prolog-nox
Suggested packages:
  prolog-el
The following NEW packages will be installed:
  swi-prolog swi-prolog-nox



But I got this strange message :

raphy@raphy:~$ dpkg -l swi-prolog
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version                       Architecture Description
+++-==============-=============================-============-======================================
ii  swi-prolog     10.0.2-1-gb8d8f931a-nobleppa2 amd64        ISO/Edinburgh-style Prolog interpreter

So I removed those two packages and the PPA:

raphy@raphy:~$ sudo apt-get remove swi-prolog

raphy@raphy:~$ sudo apt-get remove swi-prolog-nox

raphy@raphy:/etc/apt/sources.list.d$ sudo rm swi-prolog-ubuntu-stable-noble.sources

raphy@raphy:~$ sudo apt-get update```


I found in the Official Ubuntu 24.04 Repository a bunch of libraries related to swi-prolog :

raphy@raphy:~$ sudo apt-cache search swi-prolog
elpa-ediprolog - Emacs Does Interactive Prolog
swi-prolog - ISO/Edinburgh-style Prolog interpreter
swi-prolog-bdb - Berkeley DB interface for SWI-Prolog
swi-prolog-core - ISO/Edinburgh-style Prolog interpreter - core system
swi-prolog-core-packages - ISO/Edinburgh-style Prolog interpreter - core packages
swi-prolog-doc - documentation and examples for SWI-Prolog
swi-prolog-full - ISO/Edinburgh-style Prolog interpreter - full suit
swi-prolog-java - Bidirectional interface between SWI-Prolog and Java
swi-prolog-nox - ISO/Edinburgh-style Prolog interpreter - without X support
swi-prolog-odbc - ODBC library for SWI-Prolog
swi-prolog-test - tests and checks for SWI-Prolog
swi-prolog-x - User interface library for SWI-Prolog - with X support


I installed `swi-prolog-core-packages` library :

raphy@raphy:~$ sudo apt-get install swi-prolog-core-packages
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'swi-prolog-core-packages' for regex 'swi-prolog-core-packages?'
The following additional packages will be installed:
  swi-prolog-core
Suggested packages:
  elpa-ediprolog swi-prolog-doc swi-prolog-java swi-prolog-odbc swi-prolog-bdb
  
The following NEW packages will be installed:
  swi-prolog-core swi-prolog-core-packages


Which is installed mainly in `/usr/lib` folder : 

```raphy@raphy:~$ dpkg -L swi-prolog-core-packages
/.
/usr
/usr/lib
/usr/lib/swi-prolog
/usr/lib/swi-prolog/bin
/usr/lib/swi-prolog/bin/latex2html
/usr/lib/swi-prolog/include
/usr/lib/swi-prolog/include/SWI-cpp.h
/usr/lib/swi-prolog/include/SWI-cpp2.h
/usr/lib/swi-prolog/lib
/usr/lib/swi-prolog/lib/swiplserver
/usr/lib/swi-prolog/lib/swiplserver/LICENSE
/usr/lib/swi-prolog/lib/swiplserver/__init__.py
/usr/lib/swi-prolog/lib/swiplserver/prologmqi.py
/usr/lib/swi-prolog/lib/x86_64-linux
/usr/lib/swi-prolog/lib/x86_64-linux/cgi.so
/usr/lib/swi-prolog/lib/x86_64-linux/crypt.so
/usr/lib/swi-prolog/lib/x86_64-linux/double_metaphone.so
/usr/lib/swi-prolog/lib/x86_64-linux/files.so
/usr/lib/swi-prolog/lib/x86_64-linux/hashstream.so
/usr/lib/swi-prolog/lib/x86_64-linux/http_stream.so
/usr/lib/swi-prolog/lib/x86_64-linux/inclpr.so
/usr/lib/swi-prolog/lib/x86_64-linux/isub.so
/usr/lib/swi-prolog/lib/x86_64-linux/json.so
/usr/lib/swi-prolog/lib/x86_64-linux/mallocinfo.so
/usr/lib/swi-prolog/lib/x86_64-linux/md54pl.so
/usr/lib/swi-prolog/lib/x86_64-linux/memfile.so
/usr/lib/swi-prolog/lib/x86_64-linux/ntriples.so
/usr/lib/swi-prolog/lib/x86_64-linux/pdt_console.so
/usr/lib/swi-prolog/lib/x86_64-linux/porter_stem.so
/usr/lib/swi-prolog/lib/x86_64-linux/process.so
/usr/lib/swi-prolog/lib/x86_64-linux/prolog_stream.so
/usr/lib/swi-prolog/lib/x86_64-linux/protobufs.so
/usr/lib/swi-prolog/lib/x86_64-linux/rdf_db.so
/usr/lib/swi-prolog/lib/x86_64-linux/readutil.so
/usr/lib/swi-prolog/lib/x86_64-linux/redis4pl.so
/usr/lib/swi-prolog/lib/x86_64-linux/rlimit.so
/usr/lib/swi-prolog/lib/x86_64-linux/sched.so
/usr/lib/swi-prolog/lib/x86_64-linux/sgml2pl.so
/usr/lib/swi-prolog/lib/x86_64-linux/sha4pl.so
/usr/lib/swi-prolog/lib/x86_64-linux/snowball.so
/usr/lib/swi-prolog/lib/x86_64-linux/socket.so
/usr/lib/swi-prolog/lib/x86_64-linux/streaminfo.so
/usr/lib/swi-prolog/lib/x86_64-linux/sweep-module.so
/usr/lib/swi-prolog/lib/x86_64-linux/syslog.so
/usr/lib/swi-prolog/lib/x86_64-linux/table.so
/usr/lib/swi-prolog/lib/x86_64-linux/test_cpp.so
/usr/lib/swi-prolog/lib/x86_64-linux/test_ffi.so
/usr/lib/swi-prolog/lib/x86_64-linux/tex.so
/usr/lib/swi-prolog/lib/x86_64-linux/time.so
/usr/lib/swi-prolog/lib/x86_64-linux/turtle.so
/usr/lib/swi-prolog/lib/x86_64-linux/uid.so
/usr/lib/swi-prolog/lib/x86_64-linux/unicode4pl.so
/usr/lib/swi-prolog/lib/x86_64-linux/unix.so
/usr/lib/swi-prolog/lib/x86_64-linux/uri.so
/usr/lib/swi-prolog/lib/x86_64-linux/uuid.so
/usr/lib/swi-prolog/lib/x86_64-linux/websocket.so
/usr/lib/swi-prolog/lib/x86_64-linux/zlib4pl.so
/usr/lib/swi-prolog/library
/usr/lib/swi-prolog/library/DTD
/usr/lib/swi-prolog/library/DTD/HTML4.dcl
/usr/lib/swi-prolog/library/DTD/HTML4.dtd
/usr/lib/swi-prolog/library/DTD/HTML4.soc
/usr/lib/swi-prolog/library/DTD/HTML5.dtd
/usr/lib/swi-prolog/library/DTD/HTMLlat1.ent
/usr/lib/swi-prolog/library/DTD/HTMLspec.ent
/usr/lib/swi-prolog/library/DTD/HTMLsym.ent
/usr/lib/swi-prolog/library/c14n2.pl
/usr/lib/swi-prolog/library/cgi.pl
/usr/lib/swi-prolog/library/chr
/usr/lib/swi-prolog/library/chr/a_star.pl
/usr/lib/swi-prolog/library/chr/binomialheap.pl
/usr/lib/swi-prolog/library/chr/builtins.pl
/usr/lib/swi-prolog/library/chr/chr_compiler_errors.pl
/usr/lib/swi-prolog/library/chr/chr_compiler_options.pl
/usr/lib/swi-prolog/library/chr/chr_compiler_utility.pl
/usr/lib/swi-prolog/library/chr/chr_debug.pl
/usr/lib/swi-prolog/library/chr/chr_hashtable_store.pl
/usr/lib/swi-prolog/library/chr/chr_integertable_store.pl
/usr/lib/swi-prolog/library/chr/chr_messages.pl
/usr/lib/swi-prolog/library/chr/chr_op.pl
/usr/lib/swi-prolog/library/chr/chr_runtime.pl
/usr/lib/swi-prolog/library/chr/chr_translate.pl
/usr/lib/swi-prolog/library/chr/clean_code.pl
/usr/lib/swi-prolog/library/chr/find.pl
/usr/lib/swi-prolog/library/chr/guard_entailment.pl
/usr/lib/swi-prolog/library/chr/listmap.pl
/usr/lib/swi-prolog/library/chr/pairlist.pl
/usr/lib/swi-prolog/library/chr.pl
/usr/lib/swi-prolog/library/clp
/usr/lib/swi-prolog/library/clp/clpq
/usr/lib/swi-prolog/library/clp/clpq/bb_q.pl
/usr/lib/swi-prolog/library/clp/clpq/bv_q.pl
/usr/lib/swi-prolog/library/clp/clpq/fourmotz_q.pl
/usr/lib/swi-prolog/library/clp/clpq/ineq_q.pl
/usr/lib/swi-prolog/library/clp/clpq/itf_q.pl
/usr/lib/swi-prolog/library/clp/clpq/nf_q.pl
/usr/lib/swi-prolog/library/clp/clpq/store_q.pl
/usr/lib/swi-prolog/library/clp/clpq.pl
/usr/lib/swi-prolog/library/clp/clpqr
/usr/lib/swi-prolog/library/clp/clpqr/class.pl
/usr/lib/swi-prolog/library/clp/clpqr/dump.pl
/usr/lib/swi-prolog/library/clp/clpqr/geler.pl
/usr/lib/swi-prolog/library/clp/clpqr/highlight.pl
/usr/lib/swi-prolog/library/clp/clpqr/itf.pl
/usr/lib/swi-prolog/library/clp/clpqr/ordering.pl
/usr/lib/swi-prolog/library/clp/clpqr/project.pl
/usr/lib/swi-prolog/library/clp/clpqr/redund.pl
/usr/lib/swi-prolog/library/clp/clpr
/usr/lib/swi-prolog/library/clp/clpr/bb_r.pl
/usr/lib/swi-prolog/library/clp/clpr/bv_r.pl
/usr/lib/swi-prolog/library/clp/clpr/fourmotz_r.pl
/usr/lib/swi-prolog/library/clp/clpr/ineq_r.pl
/usr/lib/swi-prolog/library/clp/clpr/itf_r.pl
/usr/lib/swi-prolog/library/clp/clpr/nf_r.pl
/usr/lib/swi-prolog/library/clp/clpr/store_r.pl
/usr/lib/swi-prolog/library/clp/clpr.pl
/usr/lib/swi-prolog/library/clp/inclpr
/usr/lib/swi-prolog/library/clp/inclpr/inclpr_consistency.pl
/usr/lib/swi-prolog/library/clp/inclpr/inclpr_core.pl
/usr/lib/swi-prolog/library/clp/inclpr/inclpr_interval_arithmetic.pl
/usr/lib/swi-prolog/library/clp/inclpr/inclpr_inversion.pl
/usr/lib/swi-prolog/library/clp/inclpr/inclpr_natural_interval_extension.pl
/usr/lib/swi-prolog/library/clp/inclpr/inclpr_newton.pl
/usr/lib/swi-prolog/library/clp/inclpr/inclpr_ordering.pl
/usr/lib/swi-prolog/library/clp/inclpr/inclpr_symbolic_processing.pl
/usr/lib/swi-prolog/library/clp/inclpr.pl
/usr/lib/swi-prolog/library/crypt.pl
/usr/lib/swi-prolog/library/doc_files.pl
/usr/lib/swi-prolog/library/doc_http.pl
/usr/lib/swi-prolog/library/doc_latex.pl
/usr/lib/swi-prolog/library/double_metaphone.pl
/usr/lib/swi-prolog/library/filesex.pl
/usr/lib/swi-prolog/library/hash_stream.pl
/usr/lib/swi-prolog/library/http
/usr/lib/swi-prolog/library/http/INDEX.pl
/usr/lib/swi-prolog/library/http/README.md
/usr/lib/swi-prolog/library/http/ax.pl
/usr/lib/swi-prolog/library/http/dcg_basics.pl
/usr/lib/swi-prolog/library/http/graphql.pl
/usr/lib/swi-prolog/library/http/html_head.pl
/usr/lib/swi-prolog/library/http/html_quasiquotations.pl
/usr/lib/swi-prolog/library/http/html_write.pl
/usr/lib/swi-prolog/library/http/http_authenticate.pl
/usr/lib/swi-prolog/library/http/http_client.pl
/usr/lib/swi-prolog/library/http/http_cookie.pl
/usr/lib/swi-prolog/library/http/http_cors.pl
/usr/lib/swi-prolog/library/http/http_digest.pl
/usr/lib/swi-prolog/library/http/http_dirindex.pl
/usr/lib/swi-prolog/library/http/http_dispatch.pl
/usr/lib/swi-prolog/library/http/http_dyn_workers.pl
/usr/lib/swi-prolog/library/http/http_error.pl
/usr/lib/swi-prolog/library/http/http_exception.pl
/usr/lib/swi-prolog/library/http/http_files.pl
/usr/lib/swi-prolog/library/http/http_header.pl
/usr/lib/swi-prolog/library/http/http_hook.pl
/usr/lib/swi-prolog/library/http/http_host.pl
/usr/lib/swi-prolog/library/http/http_json.pl
/usr/lib/swi-prolog/library/http/http_load.pl
/usr/lib/swi-prolog/library/http/http_log.pl
/usr/lib/swi-prolog/library/http/http_multipart_plugin.pl
/usr/lib/swi-prolog/library/http/http_open.pl
/usr/lib/swi-prolog/library/http/http_openid.pl
/usr/lib/swi-prolog/library/http/http_parameters.pl
/usr/lib/swi-prolog/library/http/http_path.pl
/usr/lib/swi-prolog/library/http/http_proxy.pl
/usr/lib/swi-prolog/library/http/http_pwp.pl
/usr/lib/swi-prolog/library/http/http_redis_plugin.pl
/usr/lib/swi-prolog/library/http/http_server.pl
/usr/lib/swi-prolog/library/http/http_server_files.pl
/usr/lib/swi-prolog/library/http/http_session.pl
/usr/lib/swi-prolog/library/http/http_sgml_plugin.pl
/usr/lib/swi-prolog/library/http/http_stream.pl
/usr/lib/swi-prolog/library/http/http_unix_daemon.pl
/usr/lib/swi-prolog/library/http/http_wrapper.pl
/usr/lib/swi-prolog/library/http/hub.pl
/usr/lib/swi-prolog/library/http/jquery.pl
/usr/lib/swi-prolog/library/http/js_grammar.pl
/usr/lib/swi-prolog/library/http/js_write.pl
/usr/lib/swi-prolog/library/http/json.pl
/usr/lib/swi-prolog/library/http/json_convert.pl
/usr/lib/swi-prolog/library/http/mimepack.pl
/usr/lib/swi-prolog/library/http/mimetype.pl
/usr/lib/swi-prolog/library/http/term_html.pl
/usr/lib/swi-prolog/library/http/thread_httpd.pl
/usr/lib/swi-prolog/library/http/web
/usr/lib/swi-prolog/library/http/web/css
/usr/lib/swi-prolog/library/http/web/css/dirindex.css
/usr/lib/swi-prolog/library/http/web/css/openid.css
/usr/lib/swi-prolog/library/http/web/css/plterm.css
/usr/lib/swi-prolog/library/http/web/icons
/usr/lib/swi-prolog/library/http/web/icons/back.png
/usr/lib/swi-prolog/library/http/web/icons/c.png
/usr/lib/swi-prolog/library/http/web/icons/compressed.png
/usr/lib/swi-prolog/library/http/web/icons/folder.png
/usr/lib/swi-prolog/library/http/web/icons/generic.png
/usr/lib/swi-prolog/library/http/web/icons/layout.png
/usr/lib/swi-prolog/library/http/web/icons/openid-logo-square.png
/usr/lib/swi-prolog/library/http/web/icons/openid-logo-tiny.png
/usr/lib/swi-prolog/library/http/web/js
/usr/lib/swi-prolog/library/http/web/js/pengines.js
/usr/lib/swi-prolog/library/http/websocket.pl
/usr/lib/swi-prolog/library/http/yadis.pl
/usr/lib/swi-prolog/library/iso_639.pl
/usr/lib/swi-prolog/library/isub.pl
/usr/lib/swi-prolog/library/latex2html
/usr/lib/swi-prolog/library/latex2html/icons
/usr/lib/swi-prolog/library/latex2html/icons/home.gif
/usr/lib/swi-prolog/library/latex2html/icons/index.gif
/usr/lib/swi-prolog/library/latex2html/icons/info.gif
/usr/lib/swi-prolog/library/latex2html/icons/next.gif
/usr/lib/swi-prolog/library/latex2html/icons/prev.gif
/usr/lib/swi-prolog/library/latex2html/icons/up.gif
/usr/lib/swi-prolog/library/latex2html/icons/yellow_pages.gif
/usr/lib/swi-prolog/library/latex2html/latex.cmd
/usr/lib/swi-prolog/library/latex2html/latex2html.css
/usr/lib/swi-prolog/library/latex2html/latex2html.pl
/usr/lib/swi-prolog/library/latex2html/pldoc.cmd
/usr/lib/swi-prolog/library/latex2html/sty_pldoc.pl
/usr/lib/swi-prolog/library/latex2html/sty_xpce.pl
/usr/lib/swi-prolog/library/latex2html/xpce.cmd
/usr/lib/swi-prolog/library/mallocinfo.pl
/usr/lib/swi-prolog/library/md5.pl
/usr/lib/swi-prolog/library/memfile.pl
/usr/lib/swi-prolog/library/mqi.pl
/usr/lib/swi-prolog/library/paxos.pl
/usr/lib/swi-prolog/library/pdt_console.pl
/usr/lib/swi-prolog/library/pengines.pl
/usr/lib/swi-prolog/library/pengines_io.pl
/usr/lib/swi-prolog/library/pengines_sandbox.pl
/usr/lib/swi-prolog/library/pldoc
/usr/lib/swi-prolog/library/pldoc/doc_access.pl
/usr/lib/swi-prolog/library/pldoc/doc_colour.pl
/usr/lib/swi-prolog/library/pldoc/doc_html.pl
/usr/lib/swi-prolog/library/pldoc/doc_html.qlf
/usr/lib/swi-prolog/library/pldoc/doc_htmlsrc.pl
/usr/lib/swi-prolog/library/pldoc/doc_index.pl
/usr/lib/swi-prolog/library/pldoc/doc_library.pl
/usr/lib/swi-prolog/library/pldoc/doc_man.pl
/usr/lib/swi-prolog/library/pldoc/doc_modes.pl
/usr/lib/swi-prolog/library/pldoc/doc_pack.pl
/usr/lib/swi-prolog/library/pldoc/doc_process.pl
/usr/lib/swi-prolog/library/pldoc/doc_register.pl
/usr/lib/swi-prolog/library/pldoc/doc_search.pl
/usr/lib/swi-prolog/library/pldoc/doc_util.pl
/usr/lib/swi-prolog/library/pldoc/doc_wiki.pl
/usr/lib/swi-prolog/library/pldoc/doc_words.pl
/usr/lib/swi-prolog/library/pldoc/edit.png
/usr/lib/swi-prolog/library/pldoc/editpred.png
/usr/lib/swi-prolog/library/pldoc/favicon.ico
/usr/lib/swi-prolog/library/pldoc/h1-bg.png
/usr/lib/swi-prolog/library/pldoc/h2-bg.png
/usr/lib/swi-prolog/library/pldoc/hooks.pl
/usr/lib/swi-prolog/library/pldoc/man_index.pl
/usr/lib/swi-prolog/library/pldoc/multi-bg.png
/usr/lib/swi-prolog/library/pldoc/pldoc.css
/usr/lib/swi-prolog/library/pldoc/pldoc.js
/usr/lib/swi-prolog/library/pldoc/pldoc.sty
/usr/lib/swi-prolog/library/pldoc/pllisting.css
/usr/lib/swi-prolog/library/pldoc/priv-bg.png
/usr/lib/swi-prolog/library/pldoc/private.png
/usr/lib/swi-prolog/library/pldoc/pub-bg.png
/usr/lib/swi-prolog/library/pldoc/public.png
/usr/lib/swi-prolog/library/pldoc/reload.png
/usr/lib/swi-prolog/library/pldoc/source.png
/usr/lib/swi-prolog/library/pldoc/up.gif
/usr/lib/swi-prolog/library/pldoc.pl
/usr/lib/swi-prolog/library/plunit.pl
/usr/lib/swi-prolog/library/porter_stem.pl
/usr/lib/swi-prolog/library/process.pl
/usr/lib/swi-prolog/library/prolog_server.pl
/usr/lib/swi-prolog/library/prolog_stream.pl
/usr/lib/swi-prolog/library/protobufs
/usr/lib/swi-prolog/library/protobufs/gen_pb
/usr/lib/swi-prolog/library/protobufs/gen_pb/google
/usr/lib/swi-prolog/library/protobufs/gen_pb/google/protobuf
/usr/lib/swi-prolog/library/protobufs/gen_pb/google/protobuf/INDEX.pl
/usr/lib/swi-prolog/library/protobufs/gen_pb/google/protobuf/compiler
/usr/lib/swi-prolog/library/protobufs/gen_pb/google/protobuf/compiler/INDEX.pl
/usr/lib/swi-prolog/library/protobufs/gen_pb/google/protobuf/compiler/plugin_pb.pl
/usr/lib/swi-prolog/library/protobufs/gen_pb/google/protobuf/descriptor_pb.pl
/usr/lib/swi-prolog/library/protobufs/protoc-gen-swipl
/usr/lib/swi-prolog/library/protobufs.pl
/usr/lib/swi-prolog/library/pwp.pl
/usr/lib/swi-prolog/library/rdf.pl
/usr/lib/swi-prolog/library/rdf_diagram.pl
/usr/lib/swi-prolog/library/rdf_parser.pl
/usr/lib/swi-prolog/library/rdf_triple.pl
/usr/lib/swi-prolog/library/rdf_write.pl
/usr/lib/swi-prolog/library/redis.pl
/usr/lib/swi-prolog/library/redis_streams.pl
/usr/lib/swi-prolog/library/rewrite_term.pl
/usr/lib/swi-prolog/library/rlimit.pl
/usr/lib/swi-prolog/library/sched.pl
/usr/lib/swi-prolog/library/semweb
/usr/lib/swi-prolog/library/semweb/INDEX.pl
/usr/lib/swi-prolog/library/semweb/dc.rdfs
/usr/lib/swi-prolog/library/semweb/eor.rdfs
/usr/lib/swi-prolog/library/semweb/owl.owl
/usr/lib/swi-prolog/library/semweb/rdf11.pl
/usr/lib/swi-prolog/library/semweb/rdf11_containers.pl
/usr/lib/swi-prolog/library/semweb/rdf_cache.pl
/usr/lib/swi-prolog/library/semweb/rdf_compare.pl
/usr/lib/swi-prolog/library/semweb/rdf_db.pl
/usr/lib/swi-prolog/library/semweb/rdf_edit.pl
/usr/lib/swi-prolog/library/semweb/rdf_http_plugin.pl
/usr/lib/swi-prolog/library/semweb/rdf_library.pl
/usr/lib/swi-prolog/library/semweb/rdf_library.ttl
/usr/lib/swi-prolog/library/semweb/rdf_litindex.pl
/usr/lib/swi-prolog/library/semweb/rdf_ntriples.pl
/usr/lib/swi-prolog/library/semweb/rdf_persistency.pl
/usr/lib/swi-prolog/library/semweb/rdf_portray.pl
/usr/lib/swi-prolog/library/semweb/rdf_prefixes.pl
/usr/lib/swi-prolog/library/semweb/rdf_sandbox.pl
/usr/lib/swi-prolog/library/semweb/rdf_turtle.pl
/usr/lib/swi-prolog/library/semweb/rdf_turtle_write.pl
/usr/lib/swi-prolog/library/semweb/rdf_zlib_plugin.pl
/usr/lib/swi-prolog/library/semweb/rdfa.pl
/usr/lib/swi-prolog/library/semweb/rdfs.pl
/usr/lib/swi-prolog/library/semweb/rdfs.rdfs
/usr/lib/swi-prolog/library/semweb/sparql_client.pl
/usr/lib/swi-prolog/library/semweb/turtle.pl
/usr/lib/swi-prolog/library/sgml.pl
/usr/lib/swi-prolog/library/sgml_write.pl
/usr/lib/swi-prolog/library/sha.pl
/usr/lib/swi-prolog/library/snowball.pl
/usr/lib/swi-prolog/library/socket.pl
/usr/lib/swi-prolog/library/stomp.pl
/usr/lib/swi-prolog/library/streaminfo.pl
/usr/lib/swi-prolog/library/streampool.pl
/usr/lib/swi-prolog/library/sweep_link.pl
/usr/lib/swi-prolog/library/syslog.pl
/usr/lib/swi-prolog/library/table.pl
/usr/lib/swi-prolog/library/table_util.pl
/usr/lib/swi-prolog/library/term_to_json.pl
/usr/lib/swi-prolog/library/test_cover.pl
/usr/lib/swi-prolog/library/test_wizard.pl
/usr/lib/swi-prolog/library/time.pl
/usr/lib/swi-prolog/library/udp_broadcast.pl
/usr/lib/swi-prolog/library/uid.pl
/usr/lib/swi-prolog/library/unicode.pl
/usr/lib/swi-prolog/library/unix.pl
/usr/lib/swi-prolog/library/uri.pl
/usr/lib/swi-prolog/library/uuid.pl
/usr/lib/swi-prolog/library/xpath.pl
/usr/lib/swi-prolog/library/xsdp_types.pl
/usr/lib/swi-prolog/library/zlib.pl
/usr/lib/swi-prolog/test
/usr/lib/swi-prolog/test/packages
/usr/lib/swi-prolog/test/packages/mqi
/usr/lib/swi-prolog/test/packages/mqi/python
/usr/lib/swi-prolog/test/packages/mqi/python/swiplserver
/usr/lib/swi-prolog/test/packages/mqi/python/swiplserver/__init__.py
/usr/lib/swi-prolog/test/packages/mqi/python/swiplserver/prologmqi.py
/usr/lib/swi-prolog/test/packages/mqi/python/test_prologserver.py
/usr/share
/usr/share/doc
/usr/share/doc/swi-prolog-core-packages
/usr/share/doc/swi-prolog-core-packages/copyright
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/swi-prolog-core-packages
/usr/share/texmf
/usr/share/texmf/tex
/usr/share/texmf/tex/latex
/usr/share/texmf/tex/latex/swi-prolog
/usr/lib/swi-prolog/library/http/web/js/jquery-1.11.3.min.js
/usr/share/doc/swi-prolog-core-packages/NEWS.Debian.gz
/usr/share/doc/swi-prolog-core-packages/changelog.Debian.gz
/usr/share/texmf/tex/latex/swi-prolog/pldoc.sty

But…:

Among the header files installed through the Official Ubuntu Repository, there are SWI-cpp.h and SWI-cpp2.h but there is no SWI-Prolog.h.

And there is no libswipl.so or swipl.so file

Is this fine?

In CMakeLists.txt I’ve set the include folder :


target_include_directories(${PROJECT_NAME} PUBLIC
    /usr/lib/swi-prolog/include
)

In main.cpp :

//#include “SWI-Prolog.h”

#include “SWI-cpp2.h”

Compiling I get error messages :

In file included from /home/raphy/Grasp/src/main.cpp:72:
/usr/lib/swi-prolog/include/SWI-cpp2.h:1645:16: error: expected nested-name-specifier before ‘PL_av’
 1645 | #define PL_A1  PL_av[0]
      |                ^~~~~
/usr/lib/swi-prolog/include/SWI-cpp2.h:1657:17: note: in expansion of macro ‘PL_A1’
 1657 | #define A1      PL_A1

And by the way SWI-cpp2.h seems also to interfere with another library installed :

/home/raphy/Grasp/builddir/_deps/dlib-src/dlib/../dlib/bayes_utils/../string/../algs.h:692: note: in expansion of macro ‘A1’
  692 |     template <typename T, typename A0, typename A1, typename A2> class funct_wrap3
/usr/lib/swi-prolog/include/SWI-cpp2.h:1646:16: error: expected nested-name-specifier before ‘PL_av’
 1646 | #define PL_A2  PL_av[1]
      |                ^~~~~
/usr/lib/swi-prolog/include/SWI-cpp2.h:1658:17: note: in expansion of macro ‘PL_A2’
 1658 | #define A2      PL_A2
      |                 ^~~~~
/home/raphy/Grasp/builddir/_deps/dlib-src/dlib/../dlib/bayes_utils/../string/../algs.h:692: note: in expansion of macro ‘A2’
  692 |     template <typename T, typename A0, typename A1, typename A2> class funct_wrap3
/usr/lib/swi-prolog/include/SWI-cpp2.h:1645:16: error: ‘PL_av’ has not been declared
 1645 | #define PL_A1  PL_av[0]



The same if I include "SWI-cpp.h" instead of SWI-cpp2.h

So.. I removed the package :

```
raphy@raphy:~$ sudo apt-get remove swi-prolog-core-packages
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  swi-prolog-core
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
  swi-prolog-core-packages
0 upgraded, 0 newly installed, 1 to remove and 5 not upgraded.
After this operation, 8,589 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 228423 files and directories currently installed.)
Removing swi-prolog-core-packages (9.0.4+dfsg-3.1ubuntu4)

swipl.so does not exist. swipl is the executable. libswipl.so is part of one of the other packages as it is the core, not a core package.

But then, it seems you can compile a properly working version. Why also install the PPA? Best you can get is a number of different versions in different places with the risk to mix them up and get something not working.

  • Built and install swi-prolog from source (that worked)
  • Use find_package(SWIPL), after pointing cmake to include <prefix>/lib/cmake/swipl

Here is a very minimal example that links against SWI-Prolog installed with <prefix> /home/jan/cmake/build

CMakeLists.txt

cmake_minimum_required(VERSION 3.22.0)
project(test)
set(CMAKE_PREFIX_PATH /home/jan/cmake/build/lib/cmake/swipl)
find_package(SWIPL)

add_executable(test test.c)
target_link_libraries(test swipl::libswipl)

test.c

#include <SWI-Prolog.h>

int
main(int argc, char **argv)
{ if ( !PL_initialise(argc, argv) )
    PL_halt(1);

  return !PL_toplevel();
}

This creates an executable test that simply executes the normal Prolog toplevel.

Steps followed:

raphy@raphy:~$ git clone --recurse-submodule https://github.com/SWI-Prolog/swipl-devel.git

raphy@raphy:~$ cd swipl-devel/
raphy@raphy:~/swipl-devel$ git submodule update
raphy@raphy:~/swipl-devel$ git submodule init

raphy@raphy:~/swipl-devel$ cmake -DINSTALL_DOCUMENTATION=OFF -GNinja -B builddir -S .

raphy@raphy:~/swipl-devel$ cmake --build builddir -j10

raphy@raphy:~/swipl-devel$ sudo cmake --install builddir/
-- Install configuration: "RelWithDebInfo"
-- Set non-toolchain portion of runtime path of "/usr/local/lib/swipl/bin/x86_64-linux/swipl" to "/usr/local/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/usr/local/lib/swipl/lib/x86_64-linux/libswipl.so.10.1.7" to "/usr/local/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/usr/local/lib/swipl/bin/x86_64-linux/swipl-win" to "/usr/local/lib/swipl/lib/x86_64-linux"
-- Set non-toolchain portion of runtime path of "/usr/local/lib/swipl/bin/x86_64-linux/swipl-ld" to "/usr/local/lib/swipl/lib/x86_64-linux"

raphy@raphy:/usr/local/lib/swipl$ ls
ABI  app  bin  boot  boot.prc  cmake  customize  demo  doc  include  lib  library  LICENSE  README.md  swipl.home

raphy@raphy:~/Grasp$ nano CMakeLists.txt :

set (CMAKE_PREFIX_PATH /usr/local/lib/swipl/cmake/swipl)

find_package(SWIPL)

target_link_libraries (${PROJECT_NAME} PUBLIC
    swipl::libswipl
)


in main.cpp : 

#include "SWI-Prolog.h

                char *av[10];
                int ac = 0;
                av[ac++] = "/usr/local/lib/swipl/bin/x86_64-linux/swipl";
                av[ac++] = "-x";
                av[ac++] = "/usr/local/lib/swipl/boot.prc";
                av[ac] = NULL;
                PL_initialise(ac, av);
                PL_halt(PL_toplevel() ? 0 : 1);

Result:

raphy@raphy:~/Grasp$ ./builddir/Grasp
Current path: "/home/raphy/Grasp"
Welcome to SWI-Prolog (threaded, 64 bits, version 10.1.7-23-g72633bbb4)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org

Is this the normal standard swi-prolog top level ?

I still miss how to call and execute prolog within C++, without abandoning my C++ program: how to call a simple prolog statement/function within my C++ program?

PS:

If I change in main.cpp the path to swipl executable and to boot.prcto :

                //av[ac++] = "/usr/local/lib/swipl/bin/x86_64-linux/swipl";
                av[ac++] = "./bin/x86_64-linux/swipl";
                av[ac++] = "-x";
                //av[ac++] = "/usr/local/lib/swipl/boot.prc";
                av[ac++] = "./boot.prc";
                av[ac] = NULL;
                PL_initialise(ac, av);
                PL_halt(PL_toplevel() ? 0 : 1);



I get the usual error message:

```raphy@raphy:~/Grasp$ ./builddir/Grasp
Current path: "/home/raphy/Grasp"
[FATAL ERROR: at Sat May 16 16:01:58 2026
	Could not open resource database "./boot.prc": No such file or directory]
Aborted (core dumped)


git clone --recurse works without a separate git update --init --recursive; and git pull --recurse works for updating. (The documentation at SWI-Prolog -- Installation on Linux, *BSD (Unix) is a bit outdated / inconsistent)

What is wrong with it? If you see things that can be improved, please file a PR against GitHub - SWI-Prolog/plweb-www: Submodule of plweb.git that contains the (wiki) web-pages · GitHub