Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem running linux command from within MATLAB

Subject: Problem running linux command from within MATLAB

From: Sebastian Gatzka

Date: 28 Apr, 2009 08:20:05

Message: 1 of 6

Hello World.

I'm using MATLAB for Post-Processing with the CFD-Software OpenFOAM (http://www.opencfd.co.uk/openfoam/).

To access some OpenFOAM results from within MATLAB I sometimes have to run an OpenFOAM linux command called 'sample'.

Unfortunately running this code like
>> unix('sample -time 8');
yields this error message concerning glib:

>> [s,w]=unix('sample')

s =

     1


w =

sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by sample)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libfiniteVolume.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libmeshTools.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libsampling.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libtriSurface.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/liblagrangian.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libOpenFOAM.so)
sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/openmpi-1.2.6/libPstream.so)

Although this looks like a problem related to the OpenFOAM software, I wanted to ask if there might be something wrong from MATLABs side?!

Do you have any ideas, what may be wrong?

Subject: Problem running linux command from within MATLAB

From: Ashish Uthama

Date: 29 Apr, 2009 13:02:58

Message: 2 of 6

On Tue, 28 Apr 2009 04:20:05 -0400, Sebastian Gatzka
<sebastian.gatzka.NOSPAM@stud.tu-darmstadt.de> wrote:

> Hello World.
>
> I'm using MATLAB for Post-Processing with the CFD-Software OpenFOAM
> (http://www.opencfd.co.uk/openfoam/).
>
> To access some OpenFOAM results from within MATLAB I sometimes have to
> run an OpenFOAM linux command called 'sample'.
>
> Unfortunately running this code like
>>> unix('sample -time 8');
> yields this error message concerning glib:
>
>>> [s,w]=unix('sample')
>
> s =
>
> 1
>
>
> w =
>
> sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version
> `GLIBCXX_3.4.9' not found (required by sample)
> sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version
> `GLIBCXX_3.4.9' not found (required by
> /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libfiniteVolume.so)
> sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version
> `GLIBCXX_3.4.9' not found (required by
> /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libmeshTools.so)
> sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version
> `GLIBCXX_3.4.9' not found (required by
> /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libsampling.so)
> sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version
> `GLIBCXX_3.4.9' not found (required by
> /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libtriSurface.so)
> sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version
> `GLIBCXX_3.4.9' not found (required by
> /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/liblagrangian.so)
> sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version
> `GLIBCXX_3.4.9' not found (required by
> /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/libOpenFOAM.so)
> sample: /usr/local/matlab/sys/os/glnxa64/libstdc++.so.6: version
> `GLIBCXX_3.4.9' not found (required by
> /home/gatzka/OpenFOAM/OpenFOAM-1.5.x/lib/linux64GccDPOpt/openmpi-1.2.6/libPstream.so)
>
> Although this looks like a problem related to the OpenFOAM software, I
> wanted to ask if there might be something wrong from MATLABs side?!
>
> Do you have any ideas, what may be wrong?


The issue might have to do with the environment variable LD_LIBRARY_PATH
(google this if you are not aware).

The GLIBC libraries are picked up based on the path, MATLAB udpates this
variable hence the GLIBC version picked from a system command inside MATLAB
might be different.

Does 'sample' work fine outside MATLAB?
If it does, your UNIX call should reset LD_LIBRARY_PATH to the same value
it has in a unix shell before calling 'sample'.

Subject: Problem running linux command from within MATLAB

From: Sebastian Gatzka

Date: 30 Apr, 2009 09:28:02

Message: 3 of 6

Thanks for your answer.
Can you tell me how I can change these settings without having permission to the appropriate files?

Subject: Problem running linux command from within MATLAB

From: Ashish Uthama

Date: 30 Apr, 2009 13:40:40

Message: 4 of 6

On Thu, 30 Apr 2009 05:28:02 -0400, Sebastian Gatzka
<sebastian.gatzka.NOSPAM@stud.tu-darmstadt.de> wrote:

> Thanks for your answer.
> Can you tell me how I can change these settings without having
> permission to the appropriate files?


LD_LIBRARY_PATH is an environment variable, you can change it for your
shell without needing any special permissions.

Subject: Problem running linux command from within MATLAB

From: Sebastian Gatzka

Date: 30 Apr, 2009 13:55:19

Message: 5 of 6

> LD_LIBRARY_PATH is an environment variable, you can change it for your
> shell without needing any special permissions.

Sounds encouraging. How can I do this?
I'm using OpenSUSE 10.3.

Subject: Problem running linux command from within MATLAB

From: Ashish Uthama

Date: 30 Apr, 2009 14:55:55

Message: 6 of 6

On Thu, 30 Apr 2009 09:55:19 -0400, Sebastian Gatzka
<sebastian.gatzka.NOSPAM@stud.tu-darmstadt.de> wrote:

>> LD_LIBRARY_PATH is an environment variable, you can change it for your
>> shell without needing any special permissions.
>
> Sounds encouraging. How can I do this?
> I'm using OpenSUSE 10.3.

Sebastian,

You did not answer my previous question:
    Does 'sample' work fine outside MATLAB?

If it does not, its not a MATLAB issue :)

If it does, your UNIX call should reset LD_LIBRARY_PATH to the same value
it has in a unix shell before calling 'sample'.

In a linux shell, do echo $LD_LIBRARY_PATH. This should give a ':'
separated list of path for shared libraries (please google LD_LIBRARY_PATH
for more info). Copy this list.

Create a shell script 'yourscript' which resets LD_LIBRARY_PATH to the
above value. Again, this will vary depending on your shell.
For tcsh use:
setenv LD_LIBRARY_PATH <copied value>
For bash use:
export LD_LIBRARY_PATH <copied value>

Then invoke your function, 'sample'.

Remember, this is a shell script which runs outside MATLAB. We are
ensuring that the LD_LIBRARY_PATH, which determines the directories we
look for shared libraries is set to something that we know will work.

Now, invoke this shell script instead of your function 'sample':
[s,w]=unix('yourscript')



Of course, you could squash it all into one line too (without having to
create this shell script):
[s,w]=uinx('setenv LD_LIBRARY_PATH <..>;sample')

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us