Re: Compiling from source on Windows fails to find DLLs

Bob Friesenhahn <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.help
Message-ID <[email protected]>
On Sun, 22 Oct 2017, Casper Gripenberg wrote:

>
> Thanks Bob,
>
> I think it must have modified the registry entries, because I
> could not find any ENV variables defined related to this.
>
> However on my GM source compilation UseInstalledMagick is not
> defined.
>
> The solution was to roll up my sleeves and read the code,
> where I found the ENV vars MAGICK_CODER/FILTER_MODULE_PATH.
>
> Setting those to the GM source bin folder solved the issue.

That is really ugly.

> But now my next questions become:
>
> 1) What if I want to distribute my app with GM included, and
> the user has their own IM or GM installation and/or apps using
> IM or GM. How do I ensure my app only loads the libraries that
> I provide with my app, and not the libs from any other distribution?

The most essential thing is to put the executable for your app in the 
same directory as all of the GM DLLs.  Just about the only thing 100% 
reliable with Windows search for DLLs is that it checks the directory 
in which the using app resides in first.  Otherwise, it does different 
things with different Windows versions, and is likely to search the 
path indicated by "PATH" (which the other app may have set!).

> Is there some way to programmatically force the GM library
> to only initialize from the path I give it? Setting ENV vars
> seems slightly unreliable, or what do you think? Is there a
> better solution?
>
> For example the docs seem to indicate that InitializeMagick()
> somehow uses the provided path for lookups, but from my
> experimentation it does not appear to do that.

It is supposed to do that if UseInstalledMagick is not defined.  The 
code supporting it is in InitializeMagickClientPathAndName() in 
magick/magick.c.  It is important to determine if the core DLL that 
you built is indeed being executed, or if the one provided by the 
other application is being executed.

The path the user provides is less reliable than the path that the OS 
itself provides to the core GM DLL.  If GetExecutionPath() is being 
invoked, then the search path is based on the DLL location.

> 2) What is another app is loaded in memory with the GM DLLs
> already active. Will that interfere with my app if I try and
> load DLLs with the same names, but most likely different versions?

The DLLs are not like OLE DLLs in that they do not act as a server and 
share state.  There is total process isolation between apps using the 
same DLLs.  However, it is necessary that the correct DLLs are used.

If you define the environment variable MAGICK_DEBUG:

MAGICK_DEBUG=Configure

and start your app with it set in its environment, then there will be 
tracing of all of the configuration (perhaps to the Windows 
application event log), including registry keys and directory search 
paths.

Bob
-- 
Bob Friesenhahn
[email protected], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
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.