1. 程式人生 > >Caffe 安裝錯誤記錄及解決辦法

Caffe 安裝錯誤記錄及解決辦法

1)Fatal error : 'tr1/tuple' file not found

ifeq ($(OSX), 1)
  CXX := /usr/bin/clang++
    CXXFLAGS += -stdlib=libstdc++
    LINKFLAGS += -stdlib=libstdc++
  # clang throws this warning for cuda headers
  WARNINGS += -Wno-unneeded-internal-declaration
  ifneq ($(findstring 10.10, $(shell sw_vers -productVersion)),)
     CXXFLAGS += -stdlib=libc++
     LINKFLAGS += -stdlib=libc++
  endif

  # gtest needs to use its own tuple to not conflict with clang
  CXXFLAGS += -DGTEST_USE_OWN_TR1_TUPLE=1
  # boost::thread is called boost_thread-mt to mark multithreading on OS X
  LIBRARIES += boost_thread-mt
  NVCCFLAGS += -DOSX

然後修改成 33a56e0 的樣子就成功了。

2) make: *** [matlab/caffe/caffe.mexmaci64] Error 255

3) make: *** [.build_release/tools/caffe.bin] Error 1

解決方法 存在上一次安裝的殘留檔案。用 make clean 清除之前的安裝,重新編譯即可

4) make: *** [runtest] Trace/BPT trap: 5

5) 錯誤:

Building with 'Xcode Clang++'.
Undefined symbols for architecture x86_64:
  "std::string::find(char, unsigned long) const", referenced from:
      boost::basic_format<char, std::char_traits<char>, std::allocator<char> >::parse(std::string const&) in libcaffe.a(math_functions.o)
      int boost::io::detail::upper_bound_from_fstring<std::string, std::ctype<char> >(std::string const&, std::string::value_type, std::ctype<char> const&, unsigned char) in libcaffe.a(math_functions.o)
  "std::string::compare(char const*) const", referenced from:
      _mexFunction in matcaffe.o
      caffe::UpgradeV0PaddingLayers(caffe::NetParameter const&, caffe::NetParameter*) in libcaffe.a(upgrade_proto.o)
      caffe::UpgradeLayerParameter(caffe::LayerParameter const&, caffe::LayerParameter*) in libcaffe.a(upgrade_proto.o)
      caffe::UpgradeV0LayerType(std::string const&) in libcaffe.a(upgrade_proto.o)
      caffe::Filler<float>* caffe::GetFiller<float>(caffe::FillerParameter const&) in libcaffe.a(dummy_data_layer.o)
      caffe::Filler<double>* caffe::GetFiller<double>(caffe::FillerParameter const&) in libcaffe.a(dummy_data_layer.o)
      caffe::WindowDataLayer<float>::DataLayerSetUp(std::vector<caffe::Blob<float>*, std::allocator<caffe::Blob<float>*> > const&, std::vector<caffe::Blob<float>*, std::allocator<caffe::Blob<float>*> >*) in libcaffe.a(window_data_layer.o)
...

在 makefile 中做如下更改

  $(MATLAB_DIR)/bin/mex $(MAT$(PROJECT)_SRC) \
      CXX="$(CXX)" \
      CXXFLAGS="\$$CXXFLAGS $(MATLAB_CXXFLAGS)" \
-     CXXLIBS="\$$CXXLIBS $(STATIC_LINK_COMMAND) $(LDFLAGS)" -output [email protected]
+     CXXLIBS="\$$CXXLIBS $(STATIC_LINK_COMMAND) $(LDFLAGS) /usr/lib/libstdc++.dylib" -output 
[email protected]

6)錯誤:

Building with 'Xcode Clang++'.
Undefined symbols for architecture x86_64:
  "_mxArrayToString", referenced from:
      init(int, mxArray_tag**, int, mxArray_tag const**) in matcaffe.o
      read_mean(int, mxArray_tag**, int, mxArray_tag const**) in matcaffe.o
      _mexFunction in matcaffe.o
  "_mxCreateCellArray_700", referenced from:
      get_weights(int, mxArray_tag**, int, mxArray_tag const**) in matcaffe.o

change the LIBRARY_DIRS section of Makefile.config to read:LIBRARY_DIRS := $(PYTHON_LIB) /Applications/MATLAB_R2014a.app/bin/maci64 /usr/local/lib /usr/lib 二、

change the mexopts.sh to include 10.10 wherever 10.7 was there ( 4 places).

7) 按下述指引進行設定 makefile

8)錯誤:

Building with 'Xcode Clang++'.
Undefined symbols for architecture x86_64:
  "google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::string const&, unsigned char*)", referenced from:
      caffe::Datum::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::FillerParameter::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::NetParameter::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::SolverParameter::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::SolverState::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::NetState::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::NetStateRule::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)

解決辦法:出處忘記了... @reking, I see boost errors, which I vaguely recall getting myself. If I recall, Caffe was seeing Matlab's internal libraries earlier in the library path than my local homebrew libraries in /usr/local/lib. Caffe might be trying to link Matlab's version of the boost library, which, needless to say, isn't compatible with Caffe.

Try changing the LIBRARY_DIRS := ... line in your Makefile.config so that the /usr/local/lib directory is before your Matlab library directory.

Mine looks like this:

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib $(MATLAB_DIR)/bin/maci64 /usr/lib

9) 錯誤:

Building with 'Xcode Clang++'.
Undefined symbols for architecture x86_64:
  "google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::string const&, unsigned char*)", referenced from:
      caffe::Datum::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::FillerParameter::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::NetParameter::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::SolverParameter::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::SolverState::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::NetState::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)
      caffe::NetStateRule::SerializeWithCachedSizesToArray(unsigned char*) const in libcaffe.a(caffe.pb.o)

解決辦法: 9) 的錯誤和 8)很相似。但是我注意到錯誤提示: clang++ .build_release/src/caffe/proto/caffe.pb.cc -stdlib=libstdc++ -DGTEST_USE_OWN_TR1_TUPLE=1

有這麼一行。在這一行裡,有 -stdlib=libstdc++ 欄位。如果其他依賴庫用 libc++ 編譯的話,那麼就會出現 9)的錯誤。解決辦法是在 Makefile 檔案裡,將帶有 libstdc++ 的行註釋掉即可。

2015.7.2 補充。今天在編譯老版本 caffe-rc2 版本的時候,又出現了一次該錯誤。但當時我是把最新版本的 makefile.config 檔案給複製過來用了,並沒有重新填寫。所以,考慮到這個情況。我又重新解壓了一次 caffe-rc2.zip 壓縮包,重新手動填寫了一次 makefile.config 檔案。再次編譯就好了。

10) Error with mexopencv

我自己的解決辦法是,在 terminal 裡輸入DYLD_INSERT_LIBRARIES=/usr/local/lib/libopencv_highgui.2.4.dylib:/usr/local/lib/libtiff.5.dylib /Applications/MATLAB_R2014b.app/bin/matlab

因為,matlab 執行 RCNN 程式碼時提示 libopencv_highgui.2.4.dylib 使用的是 Matlab 自己的。所以就在終端裡插入系統庫。 而libopencv_highgui.2.4.dylib 系統庫又要呼叫 libtiff.5.dylib, 所以再繼續插入libtiff.5.dylib

11) Issue with libopenblas.so.0

在編譯 caffe 中的最後一步,執行 make runtest 時,出現了 caffe 無法找到libopenblas.so.0 的錯誤。出現這個錯誤的原因是,從原始碼編譯 openblas時手動更改了安裝路徑。 解決方法是,建立一個軟連線到 openblas 的預設安裝路徑即可。 cd /opt sudo ln -s /usr/local/OpenBLAS/ .

然後將 openblas 的庫所在位置新增到系統環境變數 LD_LIBRARY_PATHexport LD_LIBRARY_PATH=/opt/OpenBLAS/lib/ sudo ldconfig

這時,在編譯就不會出錯了。

12) 找不到 GLIBCXX_3.4.20 檔案

Invalid MEX-file '/home/coldmoon/ComputerVision/Caffe/matlab/caffe/caffe.mexa64':
/home/coldmoon/MATLAB/R2014b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.20'
not found (required by /home/coldmoon/ComputerVision/Caffe/matlab/caffe/caffe.mexa64)

上面兩個連結指出的是,在 libstdc++.so.6 中無法找到 GLIBCXX_3.4.20時的解決辦法。但在我係統裡 OSX(10.10),情況跟上述不一樣。 通過下列命令 find / -name "libstdc++.so.6" 可以找到官方提供的庫所在路徑。 然後進入該路徑: strings ./libstdc++.so.6 | grep GLIBCXX 可以看到,官方提供的 libstdc++.so.6 已經包含了 GLIBCXX_3.4.20。這說明 caffe.mexa64所使用的庫並非官方的庫,而是 matlab 自己提供的庫 根據https://github.com/rbgirshick/rcnn/issues/13 的說法,這是LD_LIBRARY_PATH 設定不當造成的。導致了程式優先尋找 matlab 目錄下的 libstdc++.so.6。至於 matlab 究竟引用了哪裡的庫,可以通過 ldd 命令檢視。 根據 https://github.com/rbgirshick/rcnn/issues/9 在終端下,輸入ldd caffe.mexa64,可以看到一堆所引用的庫路徑。而在 matlab 的命令視窗中輸入 !ldd caffe.mexa64 則可以看到 matlab 執行 caffe 函式時,究竟在引用哪些庫。不出意外的發現,matlab 引用的庫路徑果真都是 matlab 自己的。因為其中列出一條: libstdc++.so.6 => /home/coldmoon/MATLAB/R2014b/sys/os/glnxa64/libstdc++.so.6 (0x00007f2664bb6000) 再次執行 strings ./libstdc++.so.6 | grep GLIBCXX,就可以發現,果真沒有 GLIBCXX_3.4.20.

當我把所有 !ldd caffe.mexa64 輸出的結果都放到 LD_PRELOAD 中是,!ldd這個命令會出錯,即使不給它引數也會出錯。因此, 我只把libstdc++ 放到了這個環境變數裡。最終形成一個指令碼檔案來執行 matlab

#!/bin/bash
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
echo "LDPRELOAD is:"
echo $LD_PRELOAD
/home/coldmoon/MATLAB/R2014b/bin/matlab