Search code examples
c++dlllinkershared-libraries

Shared libraries on Windows - dependencies using wrong dll


I have a C++ code that uses gdal as library. Compiled with intel c++ compiler 16 on visual studio 2013.

In the configuration, I specify the gdal library path and library file to link with:

Additional Library Directories: C:\OSGeo4W64\lib (where gdal_i.lib is)

Additional Dependencies: gdal_i.lib

It used to work a few months ago, but something must have changed in my system. Now, when I try my executable, I get a popup with error:

The ordinal 361 could not be located in the dynamic link library SSLEAY32.dll

I can fix it by copying the SSLEAY32.dll from the gdal folder in the executable folder or by removing any call to gdal from my code, but I would like to fix my system rather. How to tell Windows to look in the right directory (I played with the PATH a lot with no success).

Using Dependency Walker, it seems that the gdal.dll is not the one from my OSGEO path, but is taken from my miniconda install. Is there a clean way to fix it? I though that if a library had its dependencies in the same folder, those ones would be used.

Dependency Walker screenshot

EDIT: Solution, thanks to Naidu's answer:

add C:\OSGeo4W64\bin; at the beginning of my path, such that the correct gdal202.dll is used in priority.

but now python does not start anymore, because it is not selecting its own gdal libraries in the miniconda folder but rather in OSGeo4W64... I can get one or the other working with the same path but not both

solution place first in the PATH the directory of Miniconda python executable, then OSGeo4W64 libraries path, then Miniconda libraries path


Solution

  • Additional Library Directories will helps in only for looking up the .lib (static libraries) files, but not for DLLs.

    The DLLs are looked up as shown in the order in below link.

    https://msdn.microsoft.com/en-us/library/7d83bc18.aspx

    So now, if your intended DLL is to be picked up, then place the DLL in any of the locations in first 4 steps said in above link..... or you can edit the PATH variable of user variables of Environment variables, with your DLL location.

    Because

    User variables take precedence over system environment variables. The user path is appended to the system path.