简体   繁体   English

在Ubuntu上从Matlab调用外部脚本失败

[英]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. 我使用system()/ unix()从matlab调用了一个外部R脚本,发现共享库被错误加载。 I know the environment is wrong in matlab. 我知道在Matlab中环境是错误的。 I also tried wrapped the command in xterm or gnome-terminal but didn't make it. 我也尝试将命令包装在xterm或gnome-terminal中,但没有成功。 How can I load the correct env variables? 如何加载正确的env变量? Is there a way to reset back to the OS's env variables before the call? 有没有办法在调用之前重设回操作系统的env变量?

>> !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 发行:Ubuntu 12.04.3

R info: platform x86_64-pc-linux-gnu R信息:平台x86_64-pc-linux-gnu
arch x86_64 拱x86_64
os linux-gnu 操作系统linux-gnu
system x86_64, linux-gnu 系统x86_64,linux-gnu
status 状态
major 3 专业3
minor 0.2 小0.2
year 2013 年2013
month 09 第09个月
day 25 第25天
svn rev 63987 svn版本63987
language R 语言R
version.string R version 3.0.2 (2013-09-25) nickname Frisbee Sailing version.string R版本3.0.2(2013-09-25)昵称Frisbee Sailing

many thanks, Gary 非常感谢,加里

One solution is to change the libgfortran that you want to use. 一种解决方案是更改要使用的libgfortran。

  1. Open a terminal and cd to "local_MATLAB"/sys/os/"your_os"/ 打开一个终端,然后转到“ 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 检查libgfortran.so.3是否是指向ligfortran.so.3.0.0的符号链接并将其删除

  3. otherwise copy libgfortran.so.3 for backup in case anything goes wrong 否则,请复制libgfortran.so.3以进行备份,以防万一发生问题

  4. locate your own libgfortran and make the symbolic link point to it 找到您自己的libgfortran并使符号链接指向它

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: 如果您使用的是UNIX,则应已安装libgfortran,可以使用以下命令找到它:

locate libgfortran

Remember to restart MATLAB so the changes apply 请记住重新启动MATLAB,以便应用更改

I assume that you can run Rscript from your terminal successfully. 我假设您可以从终端成功运行Rscript。 If that is the case, then the solution your problem is that you want to use setenv inside matlab instead of !export. 如果真是这样,那么解决您的问题是,您要在matlab中使用setenv而不是!export。 You probably want to look at this question: Start application from Matlab 您可能想看一下这个问题: 从Matlab启动应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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