MATLAB Answers

0

How do I determine which libraries my MEX-file or stand-alone application requires?

I would like to know whether there is any way to determine which libraries my MEX-file or stand-alone application requires in order to execute.

1 Answer

回答者: MathWorks Support Team 2013 年 10 月 18 日
 採用された回答

For Windows PCs:
Dependency Walker is a free utility that scans any 32-bit or 64-bit Windows module (exe, dll, ocx, sys, etc.) and builds a hierarchical tree diagram of all dependent modules. For each module found, it lists all the functions that are exported by that module, and which of those functions are actually being called by other modules. Follow the instructions below to use Dependency Walker:
1. Download and install Dependency Walker from
2. Open MATLAB and issue a call to the depends executable that comes with Dependency Walker. NOTE: The following assumes that you have installed Dependency Walker in D:\Depends.
!D:\Depends\depends.exe myMexFile (or myApp.exe)
In this command, "myMexFile" or "myApp.exe" represents the MEX-file or stand-alone application for whose dependencies you are searching.
Alternatively, you can also use the following syntax and redirect the output from Dependency Walker to a text file.
!D:\Depends\depends.exe /c /f:1 /of:C:\Temp\SomeUniqueFileName.txt myMexFile (or myApp.exe)
In this command, replace "C:\Temp\SomeUniqueFileName.txt" by the full path of a text file to which Dependency Walker will write the output.
Once the text file has been generated, you can search in it for reports of any missing libraries.
In addition to loading libraries directly through dependencies, stand-alone executables generated by MATLAB and MATLAB Compiler load a number of libraries dynamically at runtime. Static analysis tools do not show these libraries. You can use Dependency Walker to create runtime Dependency Walker profiles (.DWI-files) that can then be used to determine the runtime library dependencies for your MEX-file or stand-alone executable. You can create profiles as follows after launching Dependency Walker:
1. Click File > Open and select your stand-alone executable or MEX-file.
2. Ensure that View > Full Paths is selected.
3. Click Profile > Start Profiling.
4. Click File > Save As to save the file as a .DWI-file.
Alternatively:
1. Click File > Open and select $MATLAB\bin\win32\matlab.exe to launch MATLAB
(where $MATLAB is the MATLAB root directory on your machine, as returned by typing
matlabroot
at the MATLAB Command Prompt).
2. Go to the Profile menu and select "Start Profiling." Press OK or choose some advanced options.
3. This will create a profile and start MATLAB
4. In MATLAB, execute your MEX-file or stand-alone executable.
5. Switch to Dependency Walker and, if necessary, click Window > MATLAB.EXE to select MATLAB history.
6. Click File > Save As to save the file as a .DWI-file.
For UNIX:
You can use either the 'nm' or the 'ldd' utility to determine static file dependencies.
The nm utility lists the symbols for each object file that is specified by the filename passed to it as an argument.
If no symbolic information is available for a valid input file, the nm utility reports that fact but does not consider it an error condition. For more information, type 'man nm' at a shell prompt.
The ldd utility lists the dynamic dependencies of executable files or shared objects. It lists the path names of all shared objects that are loaded when the specified filename is loaded. For more information, type 'man ldd' at a shell prompt.
At the MATLAB Command Prompt, type
!nm -u myMexFile > /tmp/SomeUniqueFileName.txt
or
!ldd -U myMexFile > /tmp/SomeUniqueFileName.txt
In these examples, replace "/tmp/SomeUniqueFileName.txt" by the full path of a text file to which the output will be written, and replace "myMexFile" by the MEX-file whose dependencies you are searching for.
Once the text file has been generated, you can search in it for reports of any missing libraries.
If the output in the text file does not help narrow down your problem, here are some other things you can try.
1. Simplify the code from which you are generating your MEX-file or stand-alone application.
2. Compile the example files shipped with MATLAB. These examples are located in $MATLAB/extern/examples/compiler for stand-alone executables and $MATLAB/extern/examples/mex for MEX-files (where $MATLAB is the MATLAB root directory on your machine, as returned by typing
matlabroot
at the MATLAB Command Prompt).
3. Use nm or ldd to create the text file described above. Send all relevant text files to support@mathworks.com.
You can use the LD_DEBUG environment variable to evaluate the runtime library dependencies. Setting this variable to 'libs' instructs the dynamic linker to list the search path and result for all libraries loaded at runtime. For more information on the LD_DEBUG variable, see:

  0 Comments

Sign in to comment.