21

How can I add /usr/local/lib to my clang library search path?

This is what I see when I list my library search paths using clang -Xlinker -v:

enter image description here

Community
  • 1
  • 1
dr_rk
  • 4,395
  • 13
  • 48
  • 74

3 Answers3

22

Is it OK to add it as environment variable?

This should work:

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib

Notice, it's LIBRARY_PATH, not LD_LIBRARY_PATH.

On the other hand, if that doesn't work for you, you should compile with the flag:

-L/usr/local/lib

And that should be sufficient, too.

EDIT: Btw, I don't know why you're using back-slashes instead of slashes... that needs explanation. Use slashes always. Even on Windows.

The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
  • Thanks for pointing out about back-slashes, corrected question. I added `LIBRARY_PATH` to `~/.bash_profile` and still the `clang -Xlinker -v` does not list and cannot find. Can I add the `-L/usr/local/lib` flag in CMake? – dr_rk Mar 24 '17 at 10:49
  • @dr_rk Yes, you can, with `target_link_libraries(MyExec -L/usr/local/lib)`. Replace `MyExec` with the object name you want to link in your cmake file. Also, note that adding stuff to bashrc isn't always the right way to do it. Just execute that command in your shell. – The Quantum Physicist Mar 24 '17 at 10:52
  • Thanks! I have managed to solve the problem using your suggestion of including with `-L` flag. I added `-L/usr/local/lib` to the `CMAKE_EXE_LINKER_FLAGS` variable. – dr_rk Mar 24 '17 at 11:15
7

With the -L flag you can add additional paths to your library path.

arved
  • 4,401
  • 4
  • 30
  • 53
-3

its, capital I (i), not capital L. Example:

clang -fsanitize=unsigned-integer-overflow,signed-integer-overflow,shift,pointer-overflow -Wall -Wno-format-extra-args -g utilities.cpp -I/Users/myName/Git/myProj/src/libs "$@" && ./a.out