Why do I get the error "Could not open library: networkdevice.dll" when running a generated executable using UDP functionality outside MATLAB?

24 views (last 30 days)
I've written a MATLAB function that uses "dsp.UDPSender" or "dsp.UDPReceiver" objects to send or receive UDP packets over a network. When I deploy this function to a standalone executable using MATLAB Coder, and try to run the EXE file outside the MATLAB environment, I get the error below:
Could not open library: networkdevice.dll.
To run the generated code outside the MATLAB environment, use the packNGo function.
The same thing happens if I have a Simulink model with "UDP Send" or "UDP Receive" blocks from DSP System Toolbox or Embedded Coder's "Host Communication" library, and I generate an executable using Simulink Coder or Embedded Coder. Upon running the EXE file, the application silently exits, and no UDP data is sent or received.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 16 Feb 2024
Edited: MathWorks Support Team on 16 Feb 2024

What This Issue Means

The errors you are encountering indicate that the Windows Desktop executable generated from your Simulink model cannot find the required DLL file "networkdevice.dll", or its dependencies. These prebuilt libraries are necessary for dsp.UDPSender/dsp.UDPReceiver objects and UDP Send/Receive blocks from DSP System Toolbox or Embedded Coder's "Host Communication" library to function outside the MATLAB environment.
 

Try This Workaround

To resolve these errors, use the "packNGo" function. This function bundles these necessary DLLs into a ZIP file for easy relocation of your project in a different Windows Desktop environment:
Once all DLLs from the packNGo archive are present in the same folder as the EXE file, you should be able to run the generated executable successfully.
Alternatively, if MATLAB or MATLAB Runtime is installed on the machine where you are running the executable, setting environment variables to the installation directory can replace manual DLL copying. For more details regarding this workflow, and general information on running generated executables with DSP functionality outside MATLAB, refer to the documentation page below:
How to run a generated executable outside MATLAB 
Important note: UDP blocks from DSP System Toolbox or Embedded Coder's "Host Communication" library are for Desktop use only. For UDP communication on embedded hardware, the "packNgo" solution is not applicable. Instead, replace the UDP blocks in your model with the appropriate ones from target-specific toolboxes and hardware support packages (e.g., Simulink Real-Time/Speedgoat, Raspberry Pi, Arduino, STM32, TI C2000). Browse our documentation for various UDP Send and UDP Receive blocks.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!