S-Function Builder: LoadLibrary failed with error 127
16 次查看(过去 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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 C Shared Library Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!