MATLAB Answers


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

I have 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 below error:
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 which sends data using a "UDP Send" block, or receives data using a "UDP Receive" block, and I generate an executable using Embedded Coder. Upon running the EXE file, the application silently exits, and no UDP data is sent or received.

1 Answer

Answer by MathWorks Support Team on 23 Apr 2019
Edited by MathWorks Support Team on 23 Apr 2019
 Accepted Answer

The executables generated from dsp.UDPSender objects, dsp.UDPReceiver objects and UDP Send/Receive blocks rely on prebuilt DLL files included with MATLAB. As suggested by the error message, the "packNGo" function packages all the relevant files including the prebuilt DLL files in a compressed ZIP file so that you can relocate, unpack, and rebuild your project in another development environment.

In this packNGo archive, you will find the required "networkdevice.dll" file. However, please make sure to copy* *all DLL files from the packNGo archive into the directory that contains the EXE file, not only "networkdevice.dll". For example, the archive may contain other required DLLs such as:


Once all DLLs from the packNGo archive are present in the same folder as the EXE file, you should be able run the generated executable successfully.

In case MATLAB or MATLAB Runtime is installed on the machine you are running the executable, you may also set the environment variables to the respective installation folder instead of manually copying the DLLs from the packNGo archive. For more details regarding this workflow, and general information on how to run a generated executable outside MATLAB, please refer to the documentation page below:

How to run a generated executable outside MATLAB


Sign in to comment.