MATLAB Answers

Netcdf error in Matlab2019a

4 views (last 30 days)
I am using Matlab 2019a on Ubuntu 18.04 and am trying to run an executable (which requires certain netcdf libraries) inside a Matlab script via system(./my_program.x). When doing so, I get the following error:
symbol lookup error: /usr/lib/x86_64-linux-gnu/ undefined symbol: ncopts
However, if I run ./my_progam.x directly from the console, it runs just fine.
Curiously, running the exact same script in Matlab 2018a also works fine.
I am wondering whether this might be because Matlab 2019a uses its own netcdf libraries, which for some reason don't work with this particular executable. I'm not too bothered by the problem, given that I can circumvent it using an earlier Matlab version, but for convenice, I was wondering whether it is possible to instruct Matlab to essentially open the standard console, and execute ./my_progam.x as much "outside" of the Matlab environment as needed, so that it works in the same way as when I do it manually.


Sign in to comment.

Accepted Answer

Cam Salzberger
Cam Salzberger on 24 Jul 2020
Hey Robert,
I haven't encountered this specific issue, but I have seen similar issues of system commands not working exactly the same as outside of MATLAB. Usually this is due to some environment variable that MATLAB modifies or creates within its environment. If you compare all environment variables (!env or !set) within and outside of MATLAB, you can see the differences.
In this case, my money would be on either PATH or LD_LIBRARY_PATH being the culprits. There isn't a way to get the environment variable values outside of MATLAB from within it (that I'm aware of). However, you could probably manually narrow down on which included paths are causing the issue and temporarily remove or reorder those, call your executable, then set it back before continuing. As long as the path you change doesn't prevent the use of the "system" command itself, that is.
oldPath = getenv('PATH');
cleanVar = onCleanup(@()setenv('PATH', oldPath));
setenv('PATH', newPath)


Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!