Search code examples
c++dylibopenblas

dyld: Library not loaded: @rpath/libopenblas.dylib


When I make my file, I have this error:

dyld: Library not loaded: @rpath/libopenblas.dylib Referenced from: /Users/danyunhe2/reinf_learning2/cpp_original/./navig_test
Reason: image not found Abort trap: 6

I tried ln -sf <original path> /usr/local/lib but it didn't work.
From brew info openblas I got:

openblas: stable 0.3.5 (bottled), HEAD [keg-only]  
Optimized BLAS library  
https://www.openblas.net/  
/usr/local/Cellar/openblas/0.3.5 (22 files, 120.7MB)  
  Poured from bottle on 2019-02-18 at 01:27:14  
From: https://github.com/Homebrew/homebrew-  core/blob/master/Formula/openblas.rb 
==> Dependencies  
Required: gcc ✔  
==> Options  
--HEAD  
    Install HEAD version  
==> Caveats  
openblas is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BLAS and LAPACK in the Accelerate framework.  

For compilers to find openblas you may need to set:  
  export LDFLAGS="-L/usr/local/opt/openblas/lib"  
  export CPPFLAGS="-I/usr/local/opt/openblas/include"  

It told me to set compiler with LDFLAGS and CPPFLAGS. I tried but it didn't work. Anyone know how to deal with this?

I have my config.mk as:

# C++ compiler
cxx=g++-7 -fopenmp 

# Compilation flags
cflags=-Wall -ansi -pedantic -O3 

# BLAS/LAPACK flags for linear algebra
lp_lflags=-framework Accelerate 


# FFTW flags (installed via Homebrew)
fftw_iflags=
fftw_lflags=-lfftw3

# libpng flags (installed via Homebrew)
png_iflags=
png_lflags=-lpng

and Makefile:

# Load the common configuration file
include config.mk

iflags=`gsl-config --cflags`
lflags=`gsl-config --libs`

objs=navigate.o reinf_learn.o common.o
src=$(patsubst %.o,%.cc,$(objs))
execs=navig_test

all:
    $(MAKE) executables

executables: $(execs)

depend: $(src)
    $(cxx) $(iflags) -MM $(src) >Makefile.dep

-include Makefile.dep

navig_test: navig_test.cc $(objs)
    $(cxx) $(cflags) $(iflags)  -o $@ $^ $(lflags)

%.o: %.cc
    $(cxx) $(cflags) $(iflags)  -c $<

clean:
    rm -f $(execs) $(objs)

.PHONY: clean all executables depend

Solution

  • On OSX it's DYLD_LIBRARY_PATH, which you need to specify at runtime like so:

    export DYLD_LIBRARY_PATH=/usr/local/opt/openblas/lib
    

    However, please appreaciate brew's warning regarding the Accelerate framework. It is way faster with many of the BLAS operations on all sorts of levels. You will just make programs run slower.