S-Function Builder: LoadLibrary failed with error 127

5 visualizaciones (últimos 30 días)
관웅 윤
관웅 윤 el 3 de Ag. de 2021
Comentada: 관웅 윤 el 30 de Ag. de 2021
I am trying to load DLL file("main_functions.dll") explicitly on simulink using s-function builder, but it failed with error 127. However, when the DLL file is loaded on MATLAB through "loadlibrary" function, it works well. The DLL file is compiled separately with MinGW64 GCC compiler, not from MATLAB coder.
Environments:
  • Windows 10
  • MinGW64 GCC Compiler(Matlab and DLL Compiler)
To verify the DLL, It was tested on MATLAB with following code successfully
result = libpointer('singlePtr', rand([1,19]));
loadlibrary("main_functions", "main_functions.h");
calllib('main_functions', 'setup');
calllib('main_functions', 'predict', input_data, result)
Here is my s-function builder code
#include <windows.h>
#include "mex.h"
void predict_params_Start_wrapper(void **pW)
{
/* Start_BEGIN */
/*
* Custom Start code goes here.
*/
SetLastError(0);
HMODULE dllhandle;
//setup_func f_setup_func;
dllhandle = LoadLibrary("main_functions.dll");
if (dllhandle != NULL) {
mexPrintf("Successfully loaded\n");
}else {
mexPrintf("Failed to load %d\n", GetLastError());
}
}
It returns "Failed to load 127". But when the DLL file is loaded on MATALB, it returns "Successfully loaded".
  2 comentarios
Robert Hartley
Robert Hartley el 27 de Ag. de 2021
For what it's worth I'm experiencing the same problem. My code previously ran without issue in Matlab 2016b but no longer in 2020b.
Do we know what else loadlibrary (Matlab's version) does besides actually load the library? Paths and what not? Is there a way to turn on some verbose output?
관웅 윤
관웅 윤 el 30 de Ag. de 2021
I have not tried different version of Matlab, because of the compatability with a third-party software in my case. Verbose output means logging compile steps? There is an option to show log in S-function builer.

Iniciar sesión para comentar.

Respuesta aceptada

Yongjian Feng
Yongjian Feng el 3 de Ag. de 2021
On Windows, the env var PATH is used to find the dll to load. Maybe you need to play with this env var? Also does this main_functions.dll depend on other dlls? If so the PATH needs to point to those dlls as well.
  2 comentarios
관웅 윤
관웅 윤 el 4 de Ag. de 2021
Editada: 관웅 윤 el 4 de Ag. de 2021
Thank you for the answer :) I copied "main_functions.dll" to "C:\Windows\System32" which is added on the PATH variable initially, but it did not work. To figure out dll dependency, I analyzed "main_functions.dll" with "Dependencies" program. But only api-ms-win-* dlls is not found and these dll is not the problem as followed this link.
Here is a list of the missing dlls from "Dependencies"
  • api-ms-win-core-comm-l1-1-0.dll
  • api-ms-win-core-wow64-l1-1-1.dll
  • api-ms-win-core-wow64-l1-1-0.dll
  • api-ms-win-core-xstate-l2-1-0.dll
  • api-ms-win-core-xstate-l2-1-1.dll
  • api-ms-win-core-psapi-l1-1-0.dll
  • api-ms-win-core-psapi-ansi-l1-1-0.dll
  • api-ms-win-core-stringansi-l1-1-0.dll
Yongjian Feng
Yongjian Feng el 4 de Ag. de 2021
One way to narrow it down is to use a "HelloWorld" c++ dll. Write a simple C++ dll with basically no/minimum dependency, and see if it can be loaded by s-funciton builder.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Mobile en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by