S-Function Builder: LoadLibrary failed with error 127
조회 수: 5 (최근 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
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?
채택된 답변
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
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!