Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Matlab can't find a shared library when running a mex file

345 views
Skip to first unread message

vulpes

unread,
Aug 29, 2007, 8:31:44 AM8/29/07
to
Running 32-bit SuSe Linux and Matlab 7.1.

I have a single mex file a.mexglx that needs to be linked dynamically
against a library libb.so. Compiling goes fine, mex finds the header
files of the library. But when I call !ldd a.mexglx | grep libb.so
from Matlab I get

libb.so => not found

I have the library in the same directory than the mex file, I have
compiled with the command
mex -L. -lb a.cpp
and I have tried adding . to both the system path and Matlab path.
Still nothing. Any ideas on how to find the problem? And, by the way,
how can I link mex files with a library that does not have a name
lib*.so?

Thanks.

Joachim

unread,
Aug 29, 2007, 9:14:55 AM8/29/07
to
vulpes <niko....@tkk.fi> wrote in message
<1188390704.9...@k79g2000hse.googlegroups.com>...

> Running 32-bit SuSe Linux and Matlab 7.1.
>
> I have a single mex file a.mexglx that needs to be linked
dynamically
> against a library libb.so. Compiling goes fine, mex finds
the header
> files of the library. But when I call !ldd a.mexglx | grep
libb.so
> from Matlab I get
>
> libb.so => not found
>
> I have the library in the same directory than the mex
file, I have
> compiled with the command
> mex -L. -lb a.cpp
> and I have tried adding . to both the system path and
Matlab path.

Is the folder containing libb.so in your LD_LIBRARY_PATH?
You can check that via "getenv LD_LIBRARY_PATH" before
calling the mex-function.

Also, people might be able to help you better if you tell us
what the error message is when you try to call the mex-file.
I suppose you get unresolved symbols?

Joachim

>
> Thanks.
>

Peter Boettcher

unread,
Aug 29, 2007, 9:34:03 AM8/29/07
to
vulpes <niko....@tkk.fi> writes:

You can also add hardcode the directory location into the MEX file
using the linker command -rpath. Google for syntax. You'll probably
have to execute the link command by hand: use mex -v to see the full
gcc command line, copy-and-paste it, modify as appropriate, and run
it.

Or add the directory to the system ld.so.conf (/etc/ld.so.conf or the
directory /etc/ld.so.conf.d) and run ldconfig. All as root of course.

-Peter

vulpes

unread,
Aug 29, 2007, 9:42:25 AM8/29/07
to
Yeah, that was that. I just couldn't find the variable Matlab uses for
finding the libraries even though I went through the options files and all
that. After calling a shell script:

setenv $LD_LIBRARY_PATH <directory>
matlab

it worked. I already have to use the script to set LD_PRELOAD correctly
before running matlab so it doesn't really matter that much.

Thanks!

vulpes

unread,
Aug 29, 2007, 9:45:34 AM8/29/07
to
Peter Boettcher wrote:
> You can also add hardcode the directory location into the MEX file
> using the linker command -rpath. Google for syntax. You'll probably
> have to execute the link command by hand: use mex -v to see the full
> gcc command line, copy-and-paste it, modify as appropriate, and run
> it.

These are good advice, I've been wondering how to use make to create the mex
files easily. That mex -v could help in that.

> Or add the directory to the system ld.so.conf (/etc/ld.so.conf or the
> directory /etc/ld.so.conf.d) and run ldconfig. All as root of course.

Well, I don't have root rights in my lab, so...

0 new messages