coin-or / Ipopt

COIN-OR Interior Point Optimizer IPOPT
https://coin-or.github.io/Ipopt
Other
1.41k stars 281 forks source link

Use LoadLibraryExA for more robust library loading #755

Closed metab0t closed 6 months ago

metab0t commented 6 months ago

The Windows DLL search path is cumbersome : https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa For example, if the libhsl.dll in located in D:\hsl directory:

D:\hsl
| - libhsl.dll
| - libmetis.dll
| - ...

The libhsl.dll depends on libmetis.dll, but LoadLibrary("D:\\hsl\\libhsl.dll") cannot load libmetis.dll in the same directory. By using LoadLibraryExA function, setting LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR flag can add the directory that contains the DLL temporarily to the beginning of the list of directories that are searched for the DLL's dependencies. In this way, libmetis.dll can be loaded successfully.

CLAassistant commented 6 months ago

CLA assistant check
All committers have signed the CLA.

svigerske commented 6 months ago

Thank you. That looks interesting. We could then just skip the first LoadLibrary() call?

metab0t commented 6 months ago

yes, the first call to LoadLibrary can be omitted. I will change it.

metab0t commented 6 months ago

I confirm that it can make libipopt-3.dll load libhsl.dll with its full path correctly.

metab0t commented 5 months ago

@svigerske Can we have a new release 3.14.15 with Windows binaries to contain this patch?

svigerske commented 5 months ago

Yes. https://github.com/coin-or/Ipopt/releases/tag/releases%2F3.14.15