Call engOpen in C code, launch functionnal matlab engine but hangs on C process

Hello, I'm testing matlab engine library with engdemo.c exemple.
Compiling the code directly with gcc:
$ export LD_LIBRARY_PATH="matlabroot/bin/glnxa64"
$ mv matlabroot/sys/os/glnxa64/libstdc++.so.6 matlabroot/sys/os/glnxa64/libstdc++.so.6.old (get rid of the clunky matlabroot/sys/os/glnxa64/libstdc++.so.6 in a dirty way and use /usr/lib/x86_64-linux-gnu/libstdc++.so.6 instead)
$ gcc -o engdemo -L matlabroot/bin/glnxa64 -lmx -leng -lm -lmex -lmat engdemo.c -Imatlabroot/extern/include
But when I run the executable, it calls engOpen(), launch a matlab command window but then hang inside the function. If I manually quit the matlab command window engOpen release the process but return NULL.
Thanks for your help!
EDIT: explicit "get rid of the clunky matlabroot/sys/os/glnxa64/libstdc++.so.6 in a dirty way and use /usr/lib/x86_64-linux-gnu/libstdc++.so.6 instead" sentence with the command used.

4 个评论

Not sure what you meant by "(get rid of the clunky matlabroot/sys/os/glnxa64/libstdc++.so.6 in a dirty way and use /usr/lib/x86_64-linux-gnu/libstdc++.so.6 instead)", and why you need that. Does it work if you don't do that?
I rename libstdc++.so.6 to libstdc++.so.6.old.
If I don't, here is the link error I get:
```
/usr/bin/ld: /opt/Matlab/R2020b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: __cxa_thread_atexit_impl: invalid needed version 48
/usr/bin/ld: /opt/Matlab/R2020b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: error adding symbols: bad value
collect2: error: ld returned 1 exit status
```
And when I said that the linker use /usr/lib/x86_64-linux-gnu/libstdc++.so.6, it is speculation, I did not verify.
Again, not a good idea. You renamed the libstdc++ shipped with matlab to force the process to use the system libstdc++. This will force matlab to use that lib as well. It can cause trouble.
Ok do you have suggestions to resolve this issue in a cleaner way ?

请先登录,再进行评论。

 采纳的回答

My hang issue was resoleved by setting the environement variable $PATH
export PATH=matlabroot/bin:$PATH
But do not understand why.

更多回答(1 个)

I had a similar problem on MatLab R2024a running on Fedora 40, linux kernel 6.8.7. My c program would stuck on engOpen() call and would not recover.
I could find the solution using
strace -f ./myprogram
This showed that to use MatLab Engine you need to install the csh package. On fedora it's simple as:
sudo dnf install tcsh
I find the documentation should have this package as a dependency since not all linux comes with csh preinstalled.

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

版本

R2020b

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by