# SWI generated executable is not loading dll's from the local directory

**URL:** <https://swi-prolog.discourse.group/t/swi-generated-executable-is-not-loading-dlls-from-the-local-directory/3678>\
**Category:** Help!\
**Created:** [March 2, 2021, 11:04pm UTC](https://swi-prolog.discourse.group/t/swi-generated-executable-is-not-loading-dlls-from-the-local-directory/3678 "2021-03-02T23:04:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![abaljeu](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/abaljeu/32/136_2.png) [@abaljeu](https://swi-prolog.discourse.group/u/abaljeu)\
**Post date:** [March 2, 2021, 11:04pm UTC](https://swi-prolog.discourse.group/t/swi-generated-executable-is-not-loading-dlls-from-the-local-directory/3678/1 "2021-03-02T23:04:42Z")

</div>

I’m using: SWI-Prolog version ???

I want the code to load DLL’s from my local directory, not from the installation. This old version cannot run because it is not loading the local DLL as I need it to. Is there a thing I can do about this, or does this need a fix to SWI itself?

2019-09-02 01:32 PM 30,720 uri.dll  
2019-09-02 01:32 PM 51,200 uuid.dll  
2019-09-02 01:32 PM 24,576 websocket.dll  
2019-09-02 01:32 PM 49,152 yaml4pl.dll  
2018-06-01 08:24 AM 122,880 zlib1.dll  
2019-09-02 01:32 PM 22,016 zlib4pl.dll  
58 File(s) 20,522,256 bytes  
3 Dir(s) 898,635,890,688 bytes free

D:\vmm builds\NewBuild\server\>startserv.exe  
ERROR: c:/program files/swipl/library/uri.pl:56: Initialization goal raised exception:  
ERROR: The specified procedure could not be found.

ERROR: In:  
ERROR: [18] throw(error(shared\_object(open,‘The specified procedure could not be found.\r\n’),context(…,\_24864)))  
ERROR: [16]   
ERROR: [15] with\_mutex(’$foreign’,load\_foreign\_library(foreign(uri),uri,default(install)))   
ERROR: [12] ‘$run\_init\_goal’(shlib:load\_foreign\_library(…)) at c:/program files/swipl/boot/init.pl:686  
ERROR: [11] catch(system:’$run\_init\_goal’(…),\_24990,system:’$initialization\_error’(\_25012,…,…)) at c:/program files/swipl/boot/init.pl:457  
ERROR: [10] catch\_with\_backtrace(system:’$run\_init\_goal’(…),\_25042,system:’$initialization\_error’(\_25064,…,…)) at c:/program files/swipl/boot/init.pl:506  
ERROR:  
ERROR: Note: some frames are missing due to last-call optimization.  
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.  
ERROR: c:/program files/swipl/library/sgml.pl:187: Initialization goal raised exception:  
ERROR: The specified procedure could not be found.

ERROR: In:  
ERROR: [18] throw(error(shared\_object(open,‘The specified procedure could not be found.\r\n’),context(…,\_28376)))  
ERROR: [16]   
ERROR: [15] with\_mutex(’$foreign’,load\_foreign\_library(foreign(sgml2pl),sgml,default(install)))   
ERROR: [12] ‘$run\_init\_goal’(shlib:load\_foreign\_library(…)) at c:/program files/swipl/boot/init.pl:686  
ERROR: [11] catch(system:’$run\_init\_goal’(…),\_28502,system:’$initialization\_error’(\_28524,…,…)) at c:/program files/swipl/boot/init.pl:457  
ERROR: [10] catch\_with\_backtrace(system:’$run\_init\_goal’(…),\_28554,system:’$initialization\_error’(\_28576,…,…)) at c:/program files/swipl/boot/init.pl:506  
ERROR:  
ERROR: Note: some frames are missing due to last-call optimization.  
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

---

<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:** [March 3, 2021, 8:24am UTC](https://swi-prolog.discourse.group/t/swi-generated-executable-is-not-loading-dlls-from-the-local-directory/3678/2 "2021-03-03T08:24:51Z")

</div>

Is this a recent problem? The latest devel release is compiled using MinGW 10, which comes with an additional runtime library `libssp-0.dll`.

You can load a dll from any directory, but you must be aware that possible dependencies of that dll must be in the dll search path. That is all mighty complex and varies significantly between Windows versions. See also win\_add\_dll\_directory/1

---

<div class="post-metadata">

**Author:** ![abaljeu](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/abaljeu/32/136_2.png) [@abaljeu](https://swi-prolog.discourse.group/u/abaljeu)\
**Post date:** [March 3, 2021, 9:22pm UTC](https://swi-prolog.discourse.group/t/swi-generated-executable-is-not-loading-dlls-from-the-local-directory/3678/3 "2021-03-03T21:22:32Z")

</div>

I only now tried to run a program I generated last year and it didn’t work. I do not want any DLL search path, everything is already in the current directory. But the system is ignoring the package I put together with all the right files and going instead to the installation.

I uninstalled SWI and then the software worked. This is not good.

---

<div class="post-metadata">

**Author:** ![abaljeu](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/abaljeu/32/136_2.png) [@abaljeu](https://swi-prolog.discourse.group/u/abaljeu)\
**Post date:** [March 6, 2021, 7:00pm UTC](https://swi-prolog.discourse.group/t/swi-generated-executable-is-not-loading-dlls-from-the-local-directory/3678/4 "2021-03-06T19:00:23Z")

</div>

```
"C:\Program Files\swipl\bin\swipl.exe" --goal=run_server 
            -o ..\..\..\build\server\startserv.exe -c load2.pl

```

This is the line to create startserv. I ran this line again to create a new executable against the latest SWI, so I have a working startserv.

But I _must_ have this fixed. I cannot live with a past version being unusable because it was on a past SWI. What can I do so startserv does not default to loading incompatible DLL’s from the latest SWI install directory?

---

<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:** [March 7, 2021, 7:57am UTC](https://swi-prolog.discourse.group/t/swi-generated-executable-is-not-loading-dlls-from-the-local-directory/3678/5 "2021-03-07T07:57:10Z")

</div>

The best way to guarantee that the correct DLLs are picked up is by copying them into the same directory as the executable. It might also be wise to make sure that environment variables such as `SWI_HOME_DIR` and `PATH` do not point at the wrong version. This is in the end just Windows DLL management.
