2014-10-17 142 views
1

我試圖建立一個依賴於SDL2庫的項目。我已經安裝並使用自制的鏈接吧:ld:找不到庫

> ls /usr/local/lib | grep SDL2 
libSDL2-2.0.0.dylib 
libSDL2.a 
libSDL2.dylib 
libSDL2_test.a 
libSDL2main.a 

我還添加了/usr/local/lib/etc/paths~/.bash_profile還有:

> cat /etc/paths 
/usr/local/lib 
/usr/local/bin 
/usr/bin 
/bin 
/usr/sbin 
/sbin 

然而,當我嘗試生成項目,我仍然得到這個錯誤:

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) 

爲什麼會發生,我該如何解決?

回答

1

/etc/paths用於可執行文件,不用於共享庫。與在.bash_profile中設置的$PATH環境變量相同。這些是在終端中鍵入命令時搜索程序的路徑。

你需要做的是改變連接器鏈接路徑。有關如何設置鏈接路徑的詳細信息,請參閱this question的答案。

對於bash,在~/.bash_profile

+0

的答案相關的問題表明改變對鏈接的呼叫,但我不會自己稱呼它;相反,它是由用於編譯項目的其他工具自動調用的。我可以在全局添加庫路徑嗎? – 2014-10-17 18:08:40

1

我加入/usr/local/lib$LIBRARY_PATH固定問題

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

而對於魚的外殼,在~/.config/fish/config.fish

set -g -x LIBRARY_PATH $LIBRARY_PATH /usr/local/lib