How can dynamic DLL libraries be found at runtime?

I have a DLL library that is external and has links configured_ Directory can be compiled and linked normally, but during runtime, it will warn that xxx.dll is not found, and through ldd xxx.exe, it will also prompt that the dynamic DLL library is not found. How can I find this DLL library during runtime? The running environment is window, can only modify the PATH directory to find it? Because this DLL belongs to another program, the location of the DLL cannot be moved.

Windows (PE-COFF) provides nothing like the RPATH mechanism on macOS (Mach-O) or Linux (ELF). Using PATH before startup or adding search paths to the LoadLibraryEx are the only ways I know of doing this.

This is really uncomfortable. I am very curious about how cmake searches for the library downloaded through pacman in mingw64 through pkg-config. Do you know this? Because I didn’t see the lib path in mingw added to PATH in the environment variable, I don’t know why I can search for the dll library through pkg-config.

Does window support setting the LD_LIBRARY_PATH variable to search for class library paths at runtime?

On Linux you have PATH and LD_LIBRARY_PATH. On Windows there is only PATH, which combines the functions of the two.
In short: you need to add appropriate paths to the PATH variable on Windows.

Okay, are there any relevant reference documents?

I don’t know any.
I am sure it’s described somewhere on the Microsoft sites, including the default places searched, and the lookup order.

All right.

There is explanatory information about the DLL search path and import library