Simulink: dynamic link library initialization routine failed
7 views (last 30 days)
Show older comments
How can I compile an S-function with an external lib? I'm trying to compile an s-function with an external library (canlib32), however, Simulink gives the following error.
Error using sfunctionwizard
Error while obtaining sizes from MEX S-function 'CANWriteKvaser' in 'CanWrite_kvaser/S-Function Builder'.
Caused by:
Error using sfunctionwizard
Invalid MEX-file 'D:\shabbirh\code\A825TB\work\CANWriteKvaser.mexw64': A dynamic link library (DLL) initialization routine failed..
I can't figure out what DLL is missing. I have included all the relevant DLLs in the matlab "current folder". Furthermore, I'm able to compile a mexw64 and properly link all the libraries on the matlab command window; I only encounter an error when I try to call my s-function in simulink.
Lastly I've also tried to find the missing DLL using dependency walker with no result. I've compared a working s-function's .mexw64 file to the failing .mexw64 file and couldn't find any difference in missing DLL's.

How can I find the missing DLL? Is there a more specific error log?
The end goal of my project is to access the error counters on my CAN device as well as the device status. The current Vehicle Network Toolbox does have these capabilities so I'm trying to write my own s-function library. Thanks in advance.
Edit: One more thing I've tried is to create an executable and call it using the system() call in a simulink s-function but it gets executed twice . How to get simulink to execute it once only? (I've also tried putting it in an If-subsystem, still gets executed twice every time the condition is true).
0 Comments
Answers (1)
Mark McBroom
on 19 Mar 2017
Simulink gives this error if any depdendent DLL's cant be found at runtime. Make sure canlib32 is on the windows path.
0 Comments
See Also
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!