System commands requiring libraries (non-matlab related) do not work when executed from a standalone app.

Dear Forum members.
I am using Matlab R2019a under Ubuntu 18.04 and compiled an standalone app, which is run using the v96 runtime.
The app uses some system commands which call OpenFOAM (c++ software + libraries), which work fine when run from Matlab themselves but do not work under the standalone app.
The error message from the terminal is: "blockMesh: error while loading shared libraries: libblockMesh.so: cannot open shared object file: No such file or directory"
blockMesh is an OpenFOAM executable (which of course runs fine from the terminal itself). When "echo "$LD_LIBRARY_PATH" is run, both OpenFOAM and Matlab libraries are presented:
/usr/lib/openfoam/openfoam2012/platforms/linux64GccDPInt32Opt/lib/sys-openmpi:/usr/lib/x86_64-linux-gnu/openmpi/lib:/home/jairogut/OpenFOAM/jairogut-v2012/platforms/linux64GccDPInt32Opt/lib:/usr/lib/openfoam/openfoam2012/site/2012/platforms/linux64GccDPInt32Opt/lib:/usr/lib/openfoam/openfoam2012/platforms/linux64GccDPInt32Opt/lib:/usr/lib/openfoam/openfoam2012/platforms/linux64GccDPInt32Opt/lib/dummy:/usr/local/MATLAB/MATLAB_Runtime/v96/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v96/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v96/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v96/extern/bin/glnxa64
So I suppose under the standalone app, system commands requiring other libraries cannot be run, right? Is there a workaround for this?
Thank you,
Jairo.

Answers (1)

Chances are you don't have the full path of the module specified when you try to call it. It's best to specify the full path in your code. What are the lines in your code where you try to use the thing?
Alternatively, but I think less desired, is to include the whole OpenFOAM executable in the CTF with the -a option when you compile.

5 Comments

Hi @Image Analyst, thanks for your reply. I just call them with system commands. For example:
system('blockMesh')
Does that work if you type it onto the commend line in a console window? If not, then it won't work in MATLAB. You might have to create a two line batch file with cd in it where you cd to the folder where blockMesh lives. Then the second line of the batch file would actually run the blockMesh program.
Thank you. That command does not work in the console but works well as a system command in the code. Understood, I have to create a two-line batch file.
So it would not be possible from the standalone app to call something like a new terminal with its bash (which has the OpenFOAM libraries) and execute system commands there?
Maybe try
fullFileName = fullfile(pwd, 'blockMesh launcher.bat');
% Write a batch file:
fid = fopen(fullFileName, 'wt');
% Change directory to wherever the executable lives.
fprintf(fid, 'cd /usr/lib/openfoam/openfoam2012/platforms/linux64GccDPInt32Opt/lib')
% Tell batch file to launch blockMesh.
fprintf(fid, 'blockMesh')
fclose(fid); % Close the batch file.
% Run the batch file.
system(fullFileName)
Adapt as needed.

Sign in to comment.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!