简体   繁体   中英

LoadLibrary at run time gets errorcode 126 when using external dynamic library

So I have a sample code (everything in c++) that I was able to compile into dll using visual studio 2019 (everything is compiled in 64bit). I have a test code that loads the compiled dll during runtime. However, as soon as I refer to another library(opencv in this case), I would get an error on the load module (126, I assume it means it couldn't find the dll file or something).

Things I've tried so far:

  1. Adding library path and include path and all the dlls from opencv to my dll doesn't cause any error. but as soon as I add "#include "opencv2/opencv.hpp" " I get 126 (the dll still builds fine).

  2. I added the same dynamic linkage to the load module (already static linked to the same library), still no dice.

Update : After checking with process monitor I found out the OpenCV module cannot be found, which is quite bizarre as I have specified the locations under Additional library directory and include directory (I used the one under vcpkg/installed). The process monitor shows that of all the places the load module was looking for the opencv dll, only the vcpkg location was not looked at.

过程监视器输出

update2: I took out all the linker to the opencv dll and the issue didn't show up on the process monitor, however, I'm still getting the code 126 .

update3: Did a quick file search, didn't even have the dll files to begin with. Downloaded the required dll and left them in the root folder of my load module, problem solved. I want my three hours back.

Did a quick file search, didn't even have the dll files to begin with. Downloaded the required dll and left them in the root folder of my load module, problem solved. I want my three hours back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM