S-Function Builder: LoadLibrary failed with error 127

조회 수: 5 (최근 30일)
관웅 윤
관웅 윤 2021년 8월 3일
댓글: 관웅 윤 2021년 8월 30일
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
Robert Hartley
Robert Hartley 2021년 8월 27일
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?
관웅 윤
관웅 윤 2021년 8월 30일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Yongjian Feng
Yongjian Feng 2021년 8월 3일
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
관웅 윤
관웅 윤 2021년 8월 4일
편집: 관웅 윤 2021년 8월 4일
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 2021년 8월 4일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Mobile에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by