我正在尝试构建一个依赖于SDL2库的项目.我用自制软件安装并链接了它:
> ls /usr/local/lib | grep SDL2
libSDL2-2.0.0.dylib
libSDL2.a
libSDL2.dylib
libSDL2_test.a
libSDL2main.a
Run Code Online (Sandbox Code Playgroud)
我还添加了/usr/local/lib我的/etc/paths和~/.bash_profile也:
> cat /etc/paths
/usr/local/lib
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试构建项目时,我仍然会收到此错误:
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' (...) '-lSDL2'
ld: library not found for -lSDL2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
为什么会发生,我该如何解决?
我通过添加/usr/local/lib到我的问题来修复此问题$LIBRARY_PATH:
对于bash,在~/.bash_profile:
export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/lib"
Run Code Online (Sandbox Code Playgroud)
对于鱼壳,在~/.config/fish/config.fish:
set -g -x LIBRARY_PATH $LIBRARY_PATH /usr/local/lib
Run Code Online (Sandbox Code Playgroud)