0

I'm currently developing a C++ app with SDL, which requires DLLs to work. Right now, it will only find DLLs in the same folder as the program. How can I make the program search in a sub-directory named "libs".

tVoss42
  • 554
  • 4
  • 16

2 Answers2

3

If you use load time linking then you need for the DLL to be located in the DLL search path. That is documented here: Dynamic-Link Library Search Order. Typically this would require that you add the DLL folder to the PATH environment variable. Now, adding a folder to the PATH environment variable is heavy weight solution to a problem. You surely don't want to do that.

On the other hand, if you switch to run time linking then you can pass the full path of your DLL to LoadLibrary. You can call GetModuleFileName to find the file name of the executable, and then pull out the directory, and add \libs\MyDll.dll. But the big downside of run time linking is that you need to use GetProcAddress for each function that you import.

Neither of these options is particularly attractive. My advice would be to change your proposed design. Put all the DLLs that the executable needs into the same directory as the executable.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
1

Add the dll folder path in the Environment Variables (be careful that the paths in there are separated by ;).

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174