35

I'm working in OSX and I'm attempting to run a make file and when I try I get the following:

ld: library not found for -lgsl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [harm] Error 1

Earlier I found out the I needed to get the gsl library and I used mac ports and typed:

sudo port install gsl

into my command line window and it seemed to isntall okay. Is the missing lgsl not configured correctly or does it not come with gsl? I tried googling lgsl but didn't get much. I've only been at programming a few days and I don't know if I was supposed to set a path, or even really how to do that.

Thanks for any help you guys could offer.

3 Answers 3

26

I just wanted to say that I had the exact problem on OSX. Rather than setting an environment variable, I used an additional compiler flag -L/opt/local/lib, which then lets one use -lgsl. I reference this answer.

2
21

I got the same issue and here is how I fixed it:

export LIBRARY_PATH=/usr/local/Cellar/gsl/1.16/lib/

I had previously installed gsl using:

brew install gsl
5
  • 14
    what is the difference between LIBRARY_PATH and LD_LIBRARY_PATH on mac? when to use them? Mar 22, 2017 at 18:49
  • and where is it documented? How did you know about that?
    – shampoo
    May 17, 2020 at 15:01
  • 1
    Chevdor thanks for sharing this, got my inkscape build moving along a little further. FWIW, /usr/local/Cellar is symlinked to /usr/local/opt i find using /usr/local/opt to be a little less brittle for use cases such as this. thanks again
    – ipatch
    Jan 3, 2021 at 20:26
  • 1
    My homebrew Cellar folder was under /opt/homebrew, not under /usr/local/. Jan 30, 2022 at 19:52
  • 2
    @WestCoastProjects LD_LIBRARY_PATH is for dynamic linking whereas LIBRARY_PATH is for static linking. Your LD_LIBRARY_PATH will contain *.dylib files (dynamic link libraries) and your LIBRARY_PATH will contain *.a files (static libraries). Often, (but not always) the path where the dylibs and static libs are stored are the same.
    – tedtanner
    Dec 2, 2022 at 21:53
6

You need to add the path for where the macports installed the gsl library to your LD_LIBRARY_PATH environment variable (or most likely into the build script environment). I believe macports stores things in /opt/local/lib

2
  • When I type echo $PATHS I get the following: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/usr/texbin Which does show that /opt/local/lib is in my paths. I've never heard of LD_LIBRARY_PATH, and it is not set when I echo $LD_LIBRARY_PATHS, so I set it with export LD_LIBRARY_PATH="/opt/local/lib", but that still does not resolve the issue. I am not doing something right still?
    – Novice C
    May 23, 2013 at 22:15
  • 2
    Minor update: I do not know what LD_LIBRARY_PATH is exactly, but I corrected the path for LIBRARY_PATH to /opt/local/lib, and got things to run smoothly.
    – Novice C
    May 29, 2013 at 1:54

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.