- Update the LD_LIBRARIES_PATH variable inside the run_testsApp.sh, as follows:
cannot find lib path when matlab standalone app calls a mex function
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to deploy an standalone app from my matlab code using mcc on linux. The code calls a mex interface that calls GDAL c libraries from matlab. I got an error of cannot find the gdal lib libgdal.so.20 when it runs to this mex function.
I hypothesize that I have to specify the first argument as the path to the matlab_runtime. This matab runtime path overwrites my LD_LIBRARY_PATH, which contains my GDAL lib path. I need to call GDAL inside of this app running can I cannot find libgdal.so.20. The hypothesis was verified by output LD_LIBRARY_PATH inside of the run. Then I append all gdal dependence to LD_LIBRARY_PATH and call gdal executables (e.g. gdalinfo). The strategy works. But when I switch back to call my mex interface instead of GDAL executables, the same problem occurs again
The code that directly uses GDAL executables (that worked) is below
function testApp(fileName)
disp(getenv('LD_LIBRARY_PATH'))
setenv('LD_LIBRARIES_PATH', [getenv('LD_LIBRARIES_PATH'),':','path_to_my_gdal_lib']);
disp(getenv('LD_LIBRARY_PATH'))
cmd=['!gdalinfo ' fileName];
eval(cmd);
end
The code that uses a compiled mex file is below
function testApp(fileName)
disp(getenv('LD_LIBRARY_PATH'))
setenv('LD_LIBRARY_PATH', [getenv('LD_LIBRARY_PATH'),':',...
'/raid-13/SFS/xinyis/apps/gdal/2.3.0/lib:',...
'/raid-13/SFS/xinyis/apps/proj/4.9.3/lib:',...
'/raid-13/SFS/xinyis/apps/mpfr/4.1.0/lib:',...
'/raid-13/SFS/xinyis/apps/mpc/1.1.0/lib:',...
'/raid-13/SFS/xinyis/apps/gmp/6.2.1/lib']);
disp(getenv('LD_LIBRARY_PATH'))
GDALLoad();
end
My GDALLoad.c function works normally in matlab where it was compiled (but not matlab runtime). The code is below
#include "gdal.h"
#include "mex.h"
#ifdef __linux__
#pragma comment (lib,"libgdal.so")
/* linux code goes here */
#elif __APPLE__
#pragma comment (lib,"libgdal.a")
#elif _WIN64
/* windows code goes here */
#pragma comment (lib,"gdal_i.lib")
#else
#error Platform not supported
#endif
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[] )
{
if ( nrhs > 0 || nlhs>0 )
{
mexErrMsgTxt("no argument is allowed.");
}
GDALAllRegister();
OGRRegisterAll();
}
I used the following comand to compile and generated an runtime app run_testApp.sh
>> mcc -m testApp.m
I use the following command to run this code
$ ./run_testApp.sh /sharedapps/matlab/2021a 'path2mydata'
0 comentarios
Respuestas (1)
Venkat Siddarth Reddy
el 16 de Feb. de 2024
Editada: Venkat Siddarth Reddy
el 16 de Feb. de 2024
Hi Xinyi,
The setenv function sets the environmental variables for that MATLAB session only. The value of that environmental variable outside of MATLAB session would either be the value defined in the operating system's environmental variables or empty character array.
To run the standalone MATLAB application:
#!/bin/sh
# ... (other parts of the script)
# Set the LD_LIBRARY_PATH to include GDAL library paths
export LD_LIBRARY_PATH="/raid-13/SFS/xinyis/apps/gdal/2.3.0/lib:/raid-13/SFS/xinyis/apps/proj/4.9.3/lib:/raid-13/SFS/xinyis/apps/mpfr/4.1.0/lib:/raid-13/SFS/xinyis/apps/mpc/1.1.0/lib:/raid-13/SFS/xinyis/apps/gmp/6.2.1/lib:$LD_LIBRARY_PATH"
# ... (rest of the script)
This should set the MATLAB Runtime environment with required environmental variables.
I hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Standalone Applications en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!