0

I tried to get the MATLAB syntax checking to work in Vim.

I used Bundle 'jrestrepo/matlab' and for syntax highlighting and it works fine. But the syntax checking doesn't work. I exported /Applications/MATLAB_R2012b.app/bin/maci64/ to PATH with:

PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
export PATH
export PATH=$PATH:/Applications/MATLAB_R2012b.app/bin/maci64

in my bash_profile and now on the command line I get:

Tierra-Gorda:~ mike$ which mlint
/Applications/MATLAB_R2012b.app/bin/maci64/mlint

Tierra-Gorda:~ mike$ mlint
dyld: Library not loaded: libtbb.dylib
  Referenced from: /Applications/MATLAB_R2012b.app/bin/maci64/./libmwfl.dylib
  Reason: image not found
Trace/BPT trap: 5

and I suspect, that the dot in the path messes it up somehow. Because the file libmwfl.dylib exists in .../maci64/libmwfl.dylib.

Thanks for any suggestions.

Amro
  • 123,847
  • 25
  • 243
  • 454
mike
  • 791
  • 11
  • 26
  • I'm not a Mac user, but perhaps you should also set `DYLD_LIBRARY_PATH`. Also worth checking out the output of `otool -L` – Amro Jul 12 '14 at 11:38
  • Please add your comment as answer and describe a little bit more, how you meant to use otool and which path to provide for future reference. I think this solved it and as soon as I figured out, what exactly fixed it, I'll accept it as answer. – mike Jul 13 '14 at 14:30

2 Answers2

1

You probably want to set the DYLD_LIBRARY_PATH environment variable in addition to PATH:

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Applications/MATLAB_R2012b.app/bin/maci64

According to man dyld:

DYLD_LIBRARY_PATH

This is a colon separated list of directories that contain libraries. The dynamic linker searches these directories before it searches the default locations for libraries. It allows you to test new versions of existing libraries.

For each library that a program uses, the dynamic linker looks for it in each directory in DYLD_LIBRARY_PATH in turn. If it still can't find the library, it then searches DYLD_FALLBACK_FRAMEWORK_PATH and DYLD_FALLBACK_LIBRARY_PATH in turn.

Use the -L option to otool(1) to discover the frameworks and shared libraries that the executable is linked against.


EDIT:

I think a safer way is to append to DYLD_FALLBACK_LIBRARY_PATH instead. That way you don't take precedence over the default search path, and possibly override libraries loaded by other programs...

Even better, you should create a launcher script (where you set DYLD_* then start mlint), as opposed to changing the environment variables globally in your bash_profile.

Amro
  • 123,847
  • 25
  • 243
  • 454
  • As you feared, after having this in my bashrc, git refused to up/download repos. The reason seemed to be curl, which was not loaded in the poper version. Where would I do this launcher script? As a bash thing - how/when would I start it with mlint? Or in vim,.. same questions. – mike Jul 18 '14 at 15:04
  • just create a wrapper `my_mlint.sh` bash script inside your profile, where you set the appropriate environment variables and launch the actual `mlint` program (that way you don't pollute the global vars). You would then invoke this script from Vim instead of calling mlint directly... I feel like I should mentioned this again, but I'm mostly a Windows user and everything I suggested above is untested :) – Amro Jul 18 '14 at 15:12
  • But then again, I guess, that in this environment the variable is set and I'd need to open a new terminal to use the git curl version. I don't know enough about bash variables, but I guess this is saved in that session. There has to be a non intrusive solution somehow! – mike Jul 18 '14 at 17:53
  • 1
    actually that's not an issue. Setting environment variables in a bash script that you execute does not affect those in the parent shell, only sub-processes that you launch from inside the script will see the modified vars. Note there is a difference between executing and sourcing a script. See this links for more info: http://superuser.com/q/176783/11293, http://wiki.bash-hackers.org/scripting/processtree, http://stackoverflow.com/q/1158091/97160 – Amro Jul 18 '14 at 18:19
  • Very nice. Thank you. Since in vim mlint is called by a plugin and I'd rather not mess with plugins, such that they get rewritten each update, I tried the fallback path. This works! Nice info for both the solution and the scope of the variables. I'd add a point, but can't by now^^. Thanks anyway! – mike Jul 18 '14 at 19:49
0

I added carefully the correct paths to certain libraries on my .bash_profile

export matlabroot="/Applications/MATLAB_R2012a.app"

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:${matlabroot}/bin/:${matlabroot}/runtime/maci64
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${matlabroot}/sys/os/maci64:${matlabroot}/bin/maci64

DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH:/usr/local/lib:/lib:/usr/lib:${matlabroot}/bin/maci64

export DYLD_FALLBACK_LIBRARY_PATH
export DYLD_LIBRARY_PATH

Rerun Terminal or Vim and it should work now. To give some credit, I found the answer here: Issue on a Matlab 2010b on MacBook Pro (Lion)

lucky85dog
  • 141
  • 1
  • 5