2017-03-22 66 views
1

protobuf 2.5已經被安裝(經由brew),並且是在路徑:如何在mac上爲google protobuf設置LD_LIBRARY_PATH(也可能是DYLD_)?

$which protoc 
/usr/local/opt/[email protected]/bin/protoc 

當編譯(caffe)它沒有被發現:這可能是由於庫路徑設置。

ld: library not found for -lprotobuf 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make[1]: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1 

哪些環境變量需要更新?我的

LD_LIBRARY_PATH 
DYLD_LIBRARY_PATH 
LIBRARY_PATH 

其組合中目前還不清楚被要求

另外:是以下路徑/usr/local/Cellar/[email protected]/2.5.0/lib正確使用?

$ll /usr/local/Cellar/[email protected]/2.5.0/lib 
total 12392 
-r--r--r-- 1 boescst admin 1120832 Feb 26 2013 libprotoc.a 
-r--r--r-- 1 boescst admin 1536576 Feb 26 2013 libprotobuf.a 
-r--r--r-- 1 boescst admin 215672 Feb 26 2013 libprotobuf-lite.a 
drwxr-xr-x 12 boescst admin  408 Feb 26 2013 . 
drwxr-xr-x 4 boescst admin  136 Mar 12 11:46 pkgconfig 
-r--r--r-- 1 boescst admin 659108 Mar 12 11:46 libprotoc.dylib 
-r--r--r-- 1 boescst admin 659108 Mar 12 11:46 libprotoc.8.dylib 
-r--r--r-- 1 boescst admin 930424 Mar 12 11:46 libprotobuf.dylib 
-r--r--r-- 1 boescst admin 930424 Mar 12 11:46 libprotobuf.8.dylib 
-r--r--r-- 1 boescst admin 138008 Mar 12 11:46 libprotobuf-lite.dylib 
-r--r--r-- 1 boescst admin 138008 Mar 12 11:46 libprotobuf-lite.8.dylib 
drwxr-xr-x 11 boescst admin  374 Mar 12 11:46 .. 

最後:我需要做的是目錄內的任何符號鏈接 - 使調用程序(caffe在我的情況)能夠找到庫?

包括的庫顯示在Makefile像這樣:

INCLUDE_DIRS += $(BLAS_INCLUDE) 
LIBRARY_DIRS += $(BLAS_LIB) 
LIBRARY_DIRS += /usr/local/Cellar/[email protected]/2.5.0/lib 


LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) 
     $(foreach library,$(LIBRARIES),-l$(library)) 

所以有一種方法打印出這些庫 - 不訴諸make -d生成265K行?

+0

這看起來像一個編譯器鏈接器錯誤,而不是缺少的運行路徑;你可能想在你的問題中包含編譯命令。通常你會做類似於'-L/path/to/lib -lprotobuf'的東西... –

+0

@ l'l l謝謝!我將添加 – javadba

+0

@ l'L'L更新OP:不清楚如何顯示從'Makefile'指令包含的庫 – javadba

回答

1

當編譯器返回錯誤:

clang: error: linker command failed with exit code 1 (use -v to see invocation) 

這表明,試圖鏈接某個庫無法定位。在大多數情況下,它通常是通知編譯器問題庫實際在哪裏。有幾種方法可以做到這一點,它取決於正在構建的東西的方式。由於您使用的是Makefile添加以下環境變量應該解決這個問題:

LIBRARY_PATH=/usr/local/Cellar/[email protected]/2.5.0/lib:$LIBRA‌​RY_PATH 

這暫時增加了庫位置的環境,使編譯器能夠找到它。

備註:在LIBRARY_PATH未被識別的情況下,LIBARY_DIRS是使用的正確變量。

+0

thx很多。我有後續問題:'-lprotobuf'錯誤已修復。現在我得到'-lboost_python'。我想知道是否有必要*手動*將每個庫添加到路徑中。是否有一些更一般的方法來解決這個問題? 'ld:找不到-lboost_python的庫' – javadba

+0

我認爲主要的問題是編譯器期望庫位於標準位置。我不使用自制軟件,雖然我認爲應該有一種方法來更新它在這種情況下使用的路徑。 'libboost_python'位於何處?您可以隨時在'〜/ .bash_profile'中設置路徑,然後它將被全局設置。 –

+1

對標準庫位置達成一致。實際上結果'boost_python'還沒有安裝 - 所以我的壞。它現在確實拿起來了 – javadba