caffe recompile libgflags.a with -fPIC error

2.9k Views Asked by At

I'm getting an error when I try to install Caffe on Linux Ubuntu 64. The error is as follows:

/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libgflags.a: error adding symbols: Bad value

I tried recompile the gflags library with -fPIC, but the error changed to as follow:

src/caffe/common.cpp: In function ‘void caffe::GlobalInit(int*, char***)’:
src/caffe/common.cpp:35:5: error: ‘::gflags’ has not been declared
::gflags::ParseCommandLineFlags(pargc, pargv, true);

I also tried to change the CMakeCache.txt of caffe to set the -fPIC, but do not work either.

1

There are 1 best solutions below

0
On

This error arrises because gflags 2.1 changed the name of the namespace from google to gflags. There are attempts by members of the caffe community to fix this error albeit they are not finalized. You should reassign the namespace from google to gflags as follows.

In files

  • caffe/include/caffe/common.hpp
  • caffe/examples/mnist/convert_mnist_data.cpp

Comment out the ifndef

// #ifndef GFLAGS_GFLAGS_H_
namespace gflags = google;
// #endif  // GFLAGS_GFLAGS_H_

This should work temporarily. You should fork and occasionally sync your caffe repo with the BVLC/caffe repo on github so that you get the latest updates of the code.