Netcdf error in Matlab2019a

5 views (last 30 days)
Robert Beyer
Robert Beyer on 24 Jul 2020
Commented: Goutam Choudhury on 11 Dec 2020
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/libnetcdff.so.6: 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.
  1 Comment
Goutam Choudhury
Goutam Choudhury on 11 Dec 2020
Hi Robert,
I am facing the same problem with MATLAB 2020a. The executable works perfectly in my 2016 version but shows the exact same error as yours in the new version. It will be easier for me to work in the new version. I tried setting new environment path by modifying the old env (getenv('PATH')) before running the system('./...') command but nothing changed. I got the same error no matter what env path is set. I am not an expert in matlab and might be missing something here. I would be grateful if you could share what exactly was causing the problem and how you solved it
Goutam

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)
system('./my_program.x')
clear('cleanVar')
-Cam

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!