简体   繁体   中英

Call external script from matlab failed on Ubuntu

I searched many times but didn't get the problem solved. I called an external R script from matlab using system()/unix() and find the shared library is mis-loaded. I know the environment is wrong in matlab. I also tried wrapped the command in xterm or gnome-terminal but didn't make it. How can I load the correct env variables? Is there a way to reset back to the OS's env variables before the call?

>> !export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/ 
   % also tried - !export LD_LIBRARY_PATH=/usr/lib64;
>> unix('Rscript /home/gary/testRF1.R')
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/usr/lib/R/library/stats/libs/stats.so':
  /usr/local/MATLAB/R2012a/sys/os/glnxa64/libgfortran.so.3: version `GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3gf)
During startup - Warning message:
package ‘stats’ in options("defaultPackages") was not found 
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/usr/lib/R/library/stats/libs/stats.so':
  /usr/local/MATLAB/R2012a/sys/os/glnxa64/libgfortran.so.3: version `GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3gf)
Error: package or namespace load failed for ‘R.matlab’
Execution halted

ans =

     1

Distribution: Ubuntu 12.04.3

R info: platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 0.2
year 2013
month 09
day 25
svn rev 63987
language R
version.string R version 3.0.2 (2013-09-25) nickname Frisbee Sailing

many thanks, Gary

One solution is to change the libgfortran that you want to use.

  1. Open a terminal and cd to "local_MATLAB"/sys/os/"your_os"/

  2. Check that libgfortran.so.3 is a symbolic link pointing to ligfortran.so.3.0.0 and remove it

  3. otherwise copy libgfortran.so.3 for backup in case anything goes wrong

  4. locate your own libgfortran and make the symbolic link point to it

On my system this would look like :

cd /usr/local/MATLAB/R2012a/sys/os/glnxa64/
rm libgfortran.so.3
ln -s -T /usr/lib/x86_64-linux-gnu/libgfortran.so.3.0.0 libgfortran.so.3

If you're on UNIX, libgfortran should already be installed, you can find it with:

locate libgfortran

Remember to restart MATLAB so the changes apply

I assume that you can run Rscript from your terminal successfully. If that is the case, then the solution your problem is that you want to use setenv inside matlab instead of !export. You probably want to look at this question: Start application from Matlab

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM