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:
LD_LIBRARY_PATH under linux

Subject: LD_LIBRARY_PATH under linux

From: Dan Shecjter

Date: 11 Jun, 2009 09:06:01

Message: 1 of 13

Hi,
I'm trying to set my LD_LIBRARY_PATH from within matlab under linux so it can find my .so that one of my .mexa64 requires...

If I try this:
p = getenv('LD_LIBRARY_PATH');
p = [p ':' pwd]
setenv('LD_LIBARARY_PATH', p);

I get the same OLD, unchanged LD_LIBRARY_PATH if I do another:
getenv('LD_LIBRARY_PATH')

I assume that matlab somehow detects me trying to change that and does not like that..

I there a normal way of achieving this from within matlab or do I have to do it externally from matlab.

Also, while on the subject...
How can I get this done in a matlab application?
I.e. if I pack the .so file inside the matlab app.. I probably need to somehow get the LD_LIBRARY_PATH or something else done to get it to work...

Any ideas?

Subject: LD_LIBRARY_PATH under linux

From: Aurelien Queffurust

Date: 11 Jun, 2009 09:56:01

Message: 2 of 13

"Dan Shecjter" <dans+matlab@houmus.org> wrote in message <h0qhdp$5o3$1@fred.mathworks.com>...
> Hi,
> I'm trying to set my LD_LIBRARY_PATH from within matlab under linux so it can find my .so that one of my .mexa64 requires...
>
> If I try this:
> p = getenv('LD_LIBRARY_PATH');
> p = [p ':' pwd]
> setenv('LD_LIBARARY_PATH', p);
>
> I get the same OLD, unchanged LD_LIBRARY_PATH if I do another:
> getenv('LD_LIBRARY_PATH')
>
> I assume that matlab somehow detects me trying to change that and does not like that..
>
> I there a normal way of achieving this from within matlab or do I have to do it externally from matlab.
>
> Also, while on the subject...
> How can I get this done in a matlab application?
> I.e. if I pack the .so file inside the matlab app.. I probably need to somehow get the LD_LIBRARY_PATH or something else done to get it to work...
>
> Any ideas?


TYou must set the variable LD_LIBRARY_PATH o in the .cshrc (or .bashrc, .tcshrc) file.

Subject: LD_LIBRARY_PATH under linux

From: Dan Shechter

Date: 11 Jun, 2009 10:59:03

Message: 3 of 13

"Aurelien Queffurust" <tug83@yahoo.fr> wrote in message <h0qkbh$9rl$1@fred.mathworks.com>...
> "Dan Shecjter" <dans+matlab@houmus.org> wrote in message <h0qhdp$5o3$1@fred.mathworks.com>...
> > Hi,
> > I'm trying to set my LD_LIBRARY_PATH from within matlab under linux so it can find my .so that one of my .mexa64 requires...
> >
> > If I try this:
> > p = getenv('LD_LIBRARY_PATH');
> > p = [p ':' pwd]
> > setenv('LD_LIBARARY_PATH', p);
> >
> > I get the same OLD, unchanged LD_LIBRARY_PATH if I do another:
> > getenv('LD_LIBRARY_PATH')
> >
> > I assume that matlab somehow detects me trying to change that and does not like that..
> >
> > I there a normal way of achieving this from within matlab or do I have to do it externally from matlab.
> >
> > Also, while on the subject...
> > How can I get this done in a matlab application?
> > I.e. if I pack the .so file inside the matlab app.. I probably need to somehow get the LD_LIBRARY_PATH or something else done to get it to work...
> >
> > Any ideas?
>
>
> TYou must set the variable LD_LIBRARY_PATH o in the .cshrc (or .bashrc, .tcshrc) file.

Thank you for the answer. This obviously works.
But the real question for me is how do I get it to work with a matlab compiled app?
The files are embedded in the CTF...
I assume they get extracted somehwere on the file-system..
but how can I set the LD_LIBRARY_PATH externally when I don't know where to?

Subject: LD_LIBRARY_PATH under linux

From: Ashish Uthama

Date: 11 Jun, 2009 16:26:31

Message: 4 of 13

On Thu, 11 Jun 2009 05:06:01 -0400, Dan Shecjter <dans+matlab@houmus.org>
wrote:

> If I try this:
> p = getenv('LD_LIBRARY_PATH');
> p = [p ':' pwd]
> setenv('LD_LIBARARY_PATH', p);
> I get the same OLD, unchanged LD_LIBRARY_PATH if I do another:
> getenv('LD_LIBRARY_PATH')


This works for me with R2008b on Debian 4.0.

Subject: LD_LIBRARY_PATH under linux

From: Ashish Uthama

Date: 11 Jun, 2009 16:31:26

Message: 5 of 13

On Thu, 11 Jun 2009 06:59:03 -0400, Dan Shechter <dans+matlab@houmus.org>
wrote:

> But the real question for me is how do I get it to work with a matlab
> compiled app?
> The files are embedded in the CTF...


  CTFROOT Returns the root of the application in deployed mode.
      ROOT = CTFROOT returns the string that is the name of the directory
      where the CTF file for the deployed application is exploded.

Subject: LD_LIBRARY_PATH under linux

From: tristram.scott@ntlworld.com (Tristram Scott)

Date: 11 Jun, 2009 16:47:48

Message: 6 of 13

Dan Shechter <dans+matlab@houmus.org> wrote:
> "Aurelien Queffurust" <tug83@yahoo.fr> wrote in message <h0qkbh$9rl$1@fred.mathworks.com>...
>> "Dan Shecjter" <dans+matlab@houmus.org> wrote in message <h0qhdp$5o3$1@fred.mathworks.com>...
>> > Hi,
>> > I'm trying to set my LD_LIBRARY_PATH from within matlab under linux so it can find my .so that one of my .mexa64 requires...
>> >
[snip]

>>
>> TYou must set the variable LD_LIBRARY_PATH o in the .cshrc (or .bashrc,
.tcshrc) file.
>
> Thank you for the answer. This obviously works.
> But the real question for me is how do I get it to work with a matlab
compiled app?
> The files are embedded in the CTF...
> I assume they get extracted somehwere on the file-system..
> but how can I set the LD_LIBRARY_PATH externally when I don't know where
to?

The usual thing to do is to specify the expected location of your libraries
on the link line when building the application. Tell your end users that
you expect to either have the libraries in the specified location (e.g.
/usr/local/lib or /opt/mystuff/lib or whatever), or in the system expected
location (/usr/lib or whatever). Otherwise, have them set the
LD_LIBRARY_PATH.

I believe MATLAB handles this by having a wrapper script around the actual
executable. The script takes care of paths etc, then calls the executable.
This is kind of why your attempt to set the variable from within MATLAB
fails. You can set the environment variable using the unix command or the
!, but that is only valid for within the shell for that command.

You might do this:

>> unix('setenv MYTHING fish;echo $MYTHING');
fish
>> unix('echo $MYTHING');
MYTHING: Undefined variable.
>>

So the subsequent call knows nothing of what you did before, because it is
in a separate shell.

--
Dr Tristram J. Scott
Energy Consultant

Subject: LD_LIBRARY_PATH under linux

From: James

Date: 2 Jul, 2009 21:50:17

Message: 7 of 13

<rant>
Original poster's problem drives me crazy. Ridiculous matlab behavior (I'm on 2009a). By modifying LD_LIBRARY_PATH, you can only add stuff to the end of the ld library path. But Matlab will not allow you to have, say, /the/path/i/need prior to matlabroot/sys/os/glnxa64.

so I need to link my stuff statically? don't like it at all!
</rant>

Subject: LD_LIBRARY_PATH under linux

From: Sandeep

Date: 8 Feb, 2010 23:02:04

Message: 8 of 13



Hi, can anyone let me know if there has been progress on this issue / if there is any solution? I've been trying to do the same thing (change LD_LIBRARY_PATH from a mex file while MATLAB is running), but the change is not recognized.

"James " <a@b.com> wrote in message <h2ja2p$sst$1@fred.mathworks.com>...
> <rant>
> Original poster's problem drives me crazy. Ridiculous matlab behavior (I'm on 2009a). By modifying LD_LIBRARY_PATH, you can only add stuff to the end of the ld library path. But Matlab will not allow you to have, say, /the/path/i/need prior to matlabroot/sys/os/glnxa64.
>
> so I need to link my stuff statically? don't like it at all!
> </rant>

Subject: LD_LIBRARY_PATH under linux

From: Joaquim Luis

Date: 9 Feb, 2010 02:52:04

Message: 9 of 13

"Aurelien Queffurust" <tug83@yahoo.fr> wrote in message <h0qkbh$9rl$1@fred.mathworks.com>...
> "Dan Shecjter" <dans+matlab@houmus.org> wrote in message <h0qhdp$5o3$1@fred.mathworks.com>...
> > Hi,
> > I'm trying to set my LD_LIBRARY_PATH from within matlab under linux so it can find my .so that one of my .mexa64 requires...
> >
> > If I try this:
> > p = getenv('LD_LIBRARY_PATH');
> > p = [p ':' pwd]
> > setenv('LD_LIBARARY_PATH', p);
> >
> > I get the same OLD, unchanged LD_LIBRARY_PATH if I do another:
> > getenv('LD_LIBRARY_PATH')
> >
> > I assume that matlab somehow detects me trying to change that and does not like that..
> >
> > I there a normal way of achieving this from within matlab or do I have to do it externally from matlab.
> >
> > Also, while on the subject...
> > How can I get this done in a matlab application?
> > I.e. if I pack the .so file inside the matlab app.. I probably need to somehow get the LD_LIBRARY_PATH or something else done to get it to work...
> >
> > Any ideas?
>

 
> TYou must set the variable LD_LIBRARY_PATH o in the .cshrc (or .bashrc, .tcshrc) file.

That is not true on Macs. For those I had to use the same method as OPs original solution.
Why Mac and Linux behave differently? That's crazy.

Subject: LD_LIBRARY_PATH under linux

From: Thomas Clark

Date: 28 Aug, 2011 10:59:12

Message: 10 of 13

Sorry, don't have much constructive to add, but to save other people the time trying, I thought I'd note that even linking the paths into a mex file using -rpath doesn't help. MATLAB STILL overrides the library paths. I don't even know how it does that...!

<rant>

TMW PLEASE NOTE: This is unacceptable!

At the very least, if you're forcing us to link to your libraries, make them thread-safe. It's not 1980 any more... People like to use all the cores on their processors. I've got memory leaks galore which I can't fix because you won't let me link against a library that works!

So I have three alternatives at the moment:
1. Not complete my PhD (Using sequential code will be so slow it'll take me past the deadline by a few months)
2. Use OCTAVE.
3. Carry on wasting days (weeks, really) deleting MATLAB library files and replacing them with symlinks to Intel/gnu ones then re-running VALGRIND to see whether the problem is fixed or not.

<end rant. sorry>

Subject: LD_LIBRARY_PATH under linux

From: Kostas

Date: 8 May, 2012 18:10:06

Message: 11 of 13

"Thomas Clark" wrote in message <j3d720$ro2$1@newscl01ah.mathworks.com>...
> Sorry, don't have much constructive to add, but to save other people the time trying, I thought I'd note that even linking the paths into a mex file using -rpath doesn't help. MATLAB STILL overrides the library paths. I don't even know how it does that...!
>
> <rant>
>
> TMW PLEASE NOTE: This is unacceptable!
>
> At the very least, if you're forcing us to link to your libraries, make them thread-safe. It's not 1980 any more... People like to use all the cores on their processors. I've got memory leaks galore which I can't fix because you won't let me link against a library that works!
>
> So I have three alternatives at the moment:
> 1. Not complete my PhD (Using sequential code will be so slow it'll take me past the deadline by a few months)
> 2. Use OCTAVE.
> 3. Carry on wasting days (weeks, really) deleting MATLAB library files and replacing them with symlinks to Intel/gnu ones then re-running VALGRIND to see whether the problem is fixed or not.
>
> <end rant. sorry>

One kind of dirty solution that seems to work for me is the following:
make it a standalone application using mcc
add the library path to the run_myfunc.sh script MANUALLY.
run it
Probably you will have to deal with some additional problems such as dependencies to 3rd software etc

Subject: LD_LIBRARY_PATH under linux

From: Yanwei Fu

Date: 26 Feb, 2014 14:19:08

Message: 12 of 13

Hi man,

you got wrong spelling on setenv:

it should be setenv('LD_LIBRARY_PATH',p);


"Dan Shecjter" <dans+matlab@houmus.org> wrote in message <h0qhdp$5o3$1@fred.mathworks.com>...
> Hi,
> I'm trying to set my LD_LIBRARY_PATH from within matlab under linux so it can find my .so that one of my .mexa64 requires...
>
> If I try this:
> p = getenv('LD_LIBRARY_PATH');
> p = [p ':' pwd]
> setenv('LD_LIBARARY_PATH', p);
>
> I get the same OLD, unchanged LD_LIBRARY_PATH if I do another:
> getenv('LD_LIBRARY_PATH')
>
> I assume that matlab somehow detects me trying to change that and does not like that..
>
> I there a normal way of achieving this from within matlab or do I have to do it externally from matlab.
>
> Also, while on the subject...
> How can I get this done in a matlab application?
> I.e. if I pack the .so file inside the matlab app.. I probably need to somehow get the LD_LIBRARY_PATH or something else done to get it to work...
>
> Any ideas?

Subject: LD_LIBRARY_PATH under linux

From: Pushpendre

Date: 17 May, 2014 03:46:13

Message: 13 of 13

Too late for your phd but I found the solution to this problem at https://github.com/kyamagu/mexopencv/issues/45
Basically we can use the flag LD_PRELOAD to override the problematic libraries.

"Thomas Clark" wrote in message <j3d720$ro2$1@newscl01ah.mathworks.com>...
> Sorry, don't have much constructive to add, but to save other people the time trying, I thought I'd note that even linking the paths into a mex file using -rpath doesn't help. MATLAB STILL overrides the library paths. I don't even know how it does that...!
>
> <rant>
>
> TMW PLEASE NOTE: This is unacceptable!
>
> At the very least, if you're forcing us to link to your libraries, make them thread-safe. It's not 1980 any more... People like to use all the cores on their processors. I've got memory leaks galore which I can't fix because you won't let me link against a library that works!
>
> So I have three alternatives at the moment:
> 1. Not complete my PhD (Using sequential code will be so slow it'll take me past the deadline by a few months)
> 2. Use OCTAVE.
> 3. Carry on wasting days (weeks, really) deleting MATLAB library files and replacing them with symlinks to Intel/gnu ones then re-running VALGRIND to see whether the problem is fixed or not.
>
> <end rant. sorry>

Tags for this Thread

No tags are associated with 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