34

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.

Novice C
  • 1,344
  • 2
  • 15
  • 27

3 Answers3

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.

Community
  • 1
  • 1
Mani
  • 473
  • 1
  • 6
  • 13
  • This doesn't work for me. Anyone else still having this problem? EDIT: This post helped: http://stackoverflow.com/questions/28441755/unable-to-link-gsl-library-in-mac-os-x – hlin117 Dec 12 '15 at 03:05
  • @hlin117 have you tried `\`gsl-config --libs\`` when linking? – zmwang Jun 07 '17 at 13:58
20

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
Chevdor
  • 664
  • 4
  • 12
  • 11
    what is the difference between `LIBRARY_PATH` and `LD_LIBRARY_PATH` on mac? when to use them? – WestCoastProjects Mar 22 '17 at 18:49
  • and where is it documented? How did you know about that? – shampoo May 17 '20 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 03 '21 at 20:26
  • 1
    My homebrew `Cellar` folder was under `/opt/homebrew`, not under `/usr/local/`. – balanceglove2 Jan 30 '22 at 19:52
  • 1
    @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 02 '22 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

Aditya Nagrath
  • 421
  • 2
  • 8
  • 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 '13 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 '13 at 01:54