# Cmake flag -DSWIPL\_INSTALL\_IN\_LIB=OFF broken on Linux (?)

**URL:** <https://swi-prolog.discourse.group/t/cmake-flag-dswipl-install-in-lib-off-broken-on-linux/5909>\
**Category:** General\
**Created:** [November 4, 2022, 2:09pm UTC](https://swi-prolog.discourse.group/t/cmake-flag-dswipl-install-in-lib-off-broken-on-linux/5909 "2022-11-04T14:09:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [November 4, 2022, 2:09pm UTC](https://swi-prolog.discourse.group/t/cmake-flag-dswipl-install-in-lib-off-broken-on-linux/5909/1 "2022-11-04T14:09:55Z")

</div>

Dear colleagues,

This works fine:

cmake -DSWIPL\_INSTALL\_IN\_LIB=OFF -DCMAKE\_INSTALL\_PREFIX=/home/gondan/swipl …  
make  
make install  
~/swipl/bin/swipl

This doesn’t:

cmake -DSWIPL\_INSTALL\_IN\_LIB= **ON** -DCMAKE\_INSTALL\_PREFIX=/home/gondan/swipl …  
make  
make install  
~/swipl/bin/swipl

☹

---

<div class="post-metadata">

**Author:** ![oskardrums](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/oskardrums/32/3594_2.png) [@oskardrums](https://swi-prolog.discourse.group/u/oskardrums)\
**Post date:** [November 4, 2022, 2:29pm UTC](https://swi-prolog.discourse.group/t/cmake-flag-dswipl-install-in-lib-off-broken-on-linux/5909/2 "2022-11-04T14:29:28Z")

</div>

What error are you getting with `-DSWIPL_INSTALL_IN_LIB=ON`?  
Perhaps there’s an old `libswipl.so` that gets picked up in this case?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [November 4, 2022, 2:34pm UTC](https://swi-prolog.discourse.group/t/cmake-flag-dswipl-install-in-lib-off-broken-on-linux/5909/3 "2022-11-04T14:34:42Z")

</div>

Not sure this is intended to work. This option exists such that libswipl.so is installed in the globally searched libraries and can be found using the general OS shared library search as opposed to the default where libswipl.so is installed in the Prolog tree and available to swipl using the so called _rpath_ mechanism. I think this should run when called using

```
 LD_LIBRARY_PATH=$HOME/swipl/lib ~/swipl/bin/swipl

```

But that doesn’t make much sense. This option was added for Linux distribution packagers who typically want it that way.

---

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [November 4, 2022, 4:29pm UTC](https://swi-prolog.discourse.group/t/cmake-flag-dswipl-install-in-lib-off-broken-on-linux/5909/4 "2022-11-04T16:29:24Z")

</div>

Thanks, Jan. I think the misunderstanding is exactly as you describe it.

---

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [November 9, 2022, 11:57am UTC](https://swi-prolog.discourse.group/t/cmake-flag-dswipl-install-in-lib-off-broken-on-linux/5909/5 "2022-11-09T11:57:41Z")

</div>

Assuming that I have the “normal” swi-prolog installation from `apt install swi-prolog`, libswipl.so seems to be found in /usr/lib/libswipl.so (not /usr/lib/swi-prolog/lib/x86\_64/libswipl.so). Assuming that I want to load the so-file from a program, how do I find the correct path? I guess it is /usr/lib in 99% of the systems, but is there an algorithm that is 100% correct?

The runtime variables do not seem to help:

gondan@PC105-C720:~$ swipl --dump-runtime-variables  
PLBASE=“/usr/lib/swi-prolog”;  
PLARCH=“x86\_64-linux”;  
PLBITS=“64”;  
PLVERSION=“80402”;  
PLSOEXT=“so”;  
PLSOPATH=“LD\_LIBRARY\_PATH”;  
PLLIBDIR=“/usr/lib/swi-prolog/lib/x86\_64-linux”;  
PLLIB=“-lswipl”;  
PLSHARED=“yes”;  
PLTHREADS=“yes”;

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [November 9, 2022, 12:15pm UTC](https://swi-prolog.discourse.group/t/cmake-flag-dswipl-install-in-lib-off-broken-on-linux/5909/6 "2022-11-09T12:15:42Z")

</div>

> [@mgondan1](#):
>
> Assuming that I want to load the so-file from a program, how do I find the correct path? I guess it is /usr/lib in 99% of the systems, but is there an algorithm that is 100% correct?

The guess is that swipl is in `<prefix>/bin` and libswipl.so in `<prefix>/lib`. It is no rule though, sometimes the OS places an architecture directory in between. I don’t remember whether dlopen() can do the normal search for you. If it can, it should fine the right library. And, if you need to link against libswipl you can simply use `-lswipl` without `-L` flags.

---

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [November 9, 2022, 12:51pm UTC](https://swi-prolog.discourse.group/t/cmake-flag-dswipl-install-in-lib-off-broken-on-linux/5909/7 "2022-11-09T12:51:19Z")

</div>

I load it manually, so dlopen() might be an option. Thanks.

---

<div class="post-metadata">

**Author:** ![nobrowser](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/nobrowser/32/4269_2.png) [@nobrowser](https://swi-prolog.discourse.group/u/nobrowser)\
**Post date:** [November 10, 2022, 12:09am UTC](https://swi-prolog.discourse.group/t/cmake-flag-dswipl-install-in-lib-off-broken-on-linux/5909/8 "2022-11-10T00:09:48Z")

</div>

This is just what pkg-config is for.

I don’t know about `apt` and the distros using it; I install swi via homebrew. I know that the offcial homebrew package for swi gets the pkg-config support wrong, and this was one of the reasons why I made my own package. (I discussed it here a couple of months ago.) But I would hope Debian & friends get pkg-config support right, so you should try using it.
